Php Arrays Filter

Hello coders today i am going to show you a php inbuilt function which is pretty much useful to filter elements from an array.

See my below example where if you want to take only those data which  are greater than 50.

For this task you don’t need to make a new array using for loop. Just use below function and you will have a new array.

 

Code is as below:

function get_age_morethan_fifty( $value)
{
return $value > 50;
}

$age_array=array(59,49,50,51,55);
print_r(array_filter($age_array,"get_age_morethan_fifty"));

 

Demo is shown in below screenshot:

==========================================

 

Blog Catagory : PHP