Q:

Write a PHP program to filter the collection using the given callback

0

Write a PHP program to filter the collection using the given callback

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
//Licence: https://bit.ly/2CFA5XY

function reject($items, $func)
{
    return array_values(array_diff($items, array_filter($items, $func)));
}
print_r(reject(['Green', 'Red', 'Black', 'White'], function ($item) {
    return strlen($item) > 4;
}));

?>

Sample Output:

Array
(
    [0] => Red
)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now