1--TEST-- 2Test array_filter() function : usage variations - anonymous callback functions 3--FILE-- 4<?php 5/* Prototype : array array_filter(array $input [, callback $callback]) 6 * Description: Filters elements from the array via the callback. 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11* Passing different anonymous callback functions with passed by value and reference arguments 12*/ 13 14echo "*** Testing array_filter() : usage variations - Anonymous callback functions ***\n"; 15 16$input = array(0, 1, -1, 10, 100, 1000, 'Hello', null); 17 18// anonymous callback function 19echo "Anonymous callback function with regular parameter and statement\n"; 20var_dump( array_filter($input, function($input) { return ($input > 1); }) ); 21 22// anonymous callback function with reference 23echo "Anonymous callback function with reference parameter\n"; 24var_dump( array_filter($input, function(&$input) { return ($input < 1); }) ); 25 26// anonymous callback function with null argument 27echo "Anonymous callback funciton with null argument\n"; 28var_dump( array_filter($input, function() { return true; }) ); 29 30// anonymous callback function with argument and null statement 31echo "Anonymous callback function with regular argument and null statement\n"; 32var_dump( array_filter($input, function($input) { }) ); 33 34echo "Done" 35?> 36--EXPECTF-- 37*** Testing array_filter() : usage variations - Anonymous callback functions *** 38Anonymous callback function with regular parameter and statement 39array(3) { 40 [3]=> 41 int(10) 42 [4]=> 43 int(100) 44 [5]=> 45 int(1000) 46} 47Anonymous callback function with reference parameter 48array(4) { 49 [0]=> 50 int(0) 51 [2]=> 52 int(-1) 53 [6]=> 54 string(5) "Hello" 55 [7]=> 56 NULL 57} 58Anonymous callback funciton with null argument 59array(8) { 60 [0]=> 61 int(0) 62 [1]=> 63 int(1) 64 [2]=> 65 int(-1) 66 [3]=> 67 int(10) 68 [4]=> 69 int(100) 70 [5]=> 71 int(1000) 72 [6]=> 73 string(5) "Hello" 74 [7]=> 75 NULL 76} 77Anonymous callback function with regular argument and null statement 78array(0) { 79} 80Done 81