filmov
tv
array_filter() to remove empty values

Показать описание
Here is an array.
$arr1 = [
1,
3,
2,
3,
4
];
We are using function array_filter() to filter the values of this array using a callback function.
Here is the callback function.
function test_odd($var)
{
return($var & 1);
}
We are calling the callback function and passing each value of the array. If callback function returns true then this value added in the result array.
$result = array_filter(
$arr1,
"test_odd"
);
Here is the final output.
print_r($result);
$arr1 = [
1,
3,
2,
3,
4
];
We are using function array_filter() to filter the values of this array using a callback function.
Here is the callback function.
function test_odd($var)
{
return($var & 1);
}
We are calling the callback function and passing each value of the array. If callback function returns true then this value added in the result array.
$result = array_filter(
$arr1,
"test_odd"
);
Here is the final output.
print_r($result);