array filter use key
$my_array = ['foo' => 1, 'hello' => 'world'];
$allowed = ['foo', 'bar'];
$filtered = array_filter(
$my_array,
function ($key) use ($allowed) {
return in_array($key, $allowed);
},
ARRAY_FILTER_USE_KEY
);
array filter use key
$my_array = ['foo' => 1, 'hello' => 'world'];
$allowed = ['foo', 'bar'];
$filtered = array_filter(
$my_array,
function ($key) use ($allowed) {
return in_array($key, $allowed);
},
ARRAY_FILTER_USE_KEY
);
php array filter syntax
$numbers = [2, 4, 6, 8, 10];
function MyFunction($number)
{
return $number > 5;
}
$filteredArray = array_filter($numbers, "MyFunction");
/**
* `$filteredArray` now contains: `[6, 8, 10]`
* NB: Use this to remove what you don't want in the array
* @see `array_map` when you want to alter/change elements
* in the array.
*/
filter value in array php return single value
?php
$data= [
0 => [1, 'test1'],
1 => [2, 'test2'],
2 => [3, 'test3'],
];
$ids = array_map(function($item) {
return $item[0];
}, $data);
var_dump($ids);
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us