Array Filter Function in PHP

In this article I explain the PHP array_filiter function.
  • 1712

Introduction 

The array_filter function is used to filters elements of an array using callback functions and returns the filtered array.

Syntax
 

array_filter(array, function)

Parameter in array_filter Function

Parameter Description
start It specifies an array.
number It specifies name of user define function.

Example of array_filter Function

<?php

function myfunction($array1)

{

if ($array1==="Mango")

  {

  return true;

  }

else

  {

  return false;

  }

}

$array1 = array("a" => "Apple", "b" => "Mango", "c" => "Orange", "Banana");

echo "<pre>";

$result = array_filter($array1,"myfunction");

print_r($result);

?>

Output

array-filter-function-in-php.jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.