1--TEST-- 2Test array_filter() function : usage variations - Different types of 'callback' function 3--FILE-- 4<?php 5/* 6* Passing different types of callback functions to array_filter() 7* with parameters and return 8* without parameter and with return 9* with parameter and without return 10* without parameter and without return 11*/ 12 13echo "*** Testing array_filter() : usage variation - different 'callback' functions***\n"; 14 15// Initialize variables 16$input = array(0, -1, 2, 3.4E-3, 'hello', "value", "key" => 4, 'null' => NULL); 17 18function callback1() 19{ 20 return 1; 21} 22echo "-- Callback function without parameter and with return --\n"; 23var_dump( array_filter($input, "callback1") ); 24 25// callback function with parameter and without return value 26function callback2($input) 27{ 28} 29echo "-- Callback function with parameter and without return --\n"; 30var_dump( array_filter($input, "callback2") ); 31 32function callback3() 33{ 34} 35echo "-- Callback function without parameter and return --\n"; 36var_dump( array_filter($input, "callback3") ); 37 38// callback function with parameter and with return value 39function callback4($input) 40{ 41 if($input > 0 ) { 42 return true; 43 } 44 else { 45 return false; 46 } 47} 48echo "-- Callback function with parameter and return --\n"; 49var_dump( array_filter($input, "callback4") ); 50 51echo "Done" 52?> 53--EXPECT-- 54*** Testing array_filter() : usage variation - different 'callback' functions*** 55-- Callback function without parameter and with return -- 56array(8) { 57 [0]=> 58 int(0) 59 [1]=> 60 int(-1) 61 [2]=> 62 int(2) 63 [3]=> 64 float(0.0034) 65 [4]=> 66 string(5) "hello" 67 [5]=> 68 string(5) "value" 69 ["key"]=> 70 int(4) 71 ["null"]=> 72 NULL 73} 74-- Callback function with parameter and without return -- 75array(0) { 76} 77-- Callback function without parameter and return -- 78array(0) { 79} 80-- Callback function with parameter and return -- 81array(5) { 82 [2]=> 83 int(2) 84 [3]=> 85 float(0.0034) 86 [4]=> 87 string(5) "hello" 88 [5]=> 89 string(5) "value" 90 ["key"]=> 91 int(4) 92} 93Done 94