1--TEST-- 2basic array_filter test 3--FILE-- 4<?php 5function odd($var) 6{ 7 return($var & 1); 8} 9 10function even($var) 11{ 12 return(!($var & 1)); 13} 14 15$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5); 16$array2 = array(6, 7, 8, 9, 10, 11, 12, 0); 17$array3 = array(TRUE, FALSE, NULL); 18 19echo "Odd :\n"; 20var_dump(array_filter($array1, "odd")); 21var_dump(array_filter($array2, "odd")); 22var_dump(array_filter($array3, "odd")); 23echo "Even:\n"; 24var_dump(array_filter($array1, "even")); 25var_dump(array_filter($array2, "even")); 26var_dump(array_filter($array3, "even")); 27 28var_dump(array_filter(array())); 29var_dump(array_filter(array(), array())); 30var_dump(array_filter("", null)); 31var_dump(array_filter($array1, 1)); 32 33echo '== DONE =='; 34?> 35--EXPECTF-- 36Odd : 37array(3) { 38 ["a"]=> 39 int(1) 40 ["c"]=> 41 int(3) 42 ["e"]=> 43 int(5) 44} 45array(3) { 46 [1]=> 47 int(7) 48 [3]=> 49 int(9) 50 [5]=> 51 int(11) 52} 53array(1) { 54 [0]=> 55 bool(true) 56} 57Even: 58array(2) { 59 ["b"]=> 60 int(2) 61 ["d"]=> 62 int(4) 63} 64array(5) { 65 [0]=> 66 int(6) 67 [2]=> 68 int(8) 69 [4]=> 70 int(10) 71 [6]=> 72 int(12) 73 [7]=> 74 int(0) 75} 76array(2) { 77 [1]=> 78 bool(false) 79 [2]=> 80 NULL 81} 82array(0) { 83} 84 85Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 86NULL 87 88Warning: array_filter() expects parameter 1 to be array, string given in %s on line %d 89NULL 90 91Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 92NULL 93== DONE == 94