filter value out array php code example
Example 1: php filter array
$numbers = [-2, 4, -6, 8, 10];
function isPositive($number)
{
return $number > 0;
}
$filteredArray = array_filter($numbers, "isPositive");
Example 2: 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);