array_filter( ) filters elements through a function : array_filter « Data Structure « PHP






array_filter( ) filters elements through a function

 
array array_filter ( array arr [, function callback] )

<?
    function endswithy($value) {
            return (substr($value, -1) == 'y');
    }

    $people = array("Johnny", "Timmy", "Bobby", "Sam", "Tammy", "Joe");
    $withy = array_filter($people, "endswithy");
    var_dump($withy);
?>
  
  








Related examples in the same category

1.Array filter
2.Filtering Arrays Using array_filter()
3.Using the array_filter() Function
4.array_filter demo