Thursday, 15 April 2021

PHP array_filter

 The array_filter() function filters the values of an array using a callback function.

This function passes each value of the input array to the callback function. If the callback function returns true, the current value from input is returned into the result array. Array keys are preserved.


<?php
function test_odd($var)
  {
  return($var & 1);
  }

$a1=array(1,3,2,3,4);
print_r(array_filter($a1,"test_odd"));
?>

Syntax

array_filter(array, callbackfunction, flag)


https://www.w3schools.com/php/func_array_filter.asp

No comments:

Post a Comment