Write a PHP program to get the last element for which the given function returns a truth value.
<?php function find_Last($items, $func) { $filteredItems = array_filter($items, $func); return array_pop($filteredItems); } echo find_Last([1, 2, 3, 4], function ($n) { return ($n % 2) === 1; }); echo "\n"; echo find_Last([1, 2, 3, 4], function ($n) { return ($n % 2) === 0; }); ?>
Sample Output:
3 4
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer