Return to array_filter_basic.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test array_filter() function : basic functionality 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: echo "*** Testing array_filter() : basic functionality ***\n"; 12: 13: 14: // Initialise all required variables 15: $input = array(1, 2, 3, 0, -1); // 0 will be considered as FALSE and removed in default callback 16: 17: /* Callback function 18: * Prototype : bool even(array $input) 19: * Parameters : $input - input array each element of which will be checked in function even() 20: * Return type : boolean - true if element is even and false otherwise 21: * Description : This function takes array as parameter and checks for each element of array. 22: * It returns true if the element is even number else returns false 23: */ 24: function even($input) 25: { 26: return ($input % 2 == 0); 27: } 28: 29: // with all possible arguments 30: var_dump( array_filter($input,"even") ); 31: 32: // with default arguments 33: var_dump( array_filter($input) ); 34: 35: echo "Done" 36: ?> 37: --EXPECTF-- 38: *** Testing array_filter() : basic functionality *** 39: array(2) { 40: [1]=> 41: int(2) 42: [3]=> 43: int(0) 44: } 45: array(4) { 46: [0]=> 47: int(1) 48: [1]=> 49: int(2) 50: [2]=> 51: int(3) 52: [4]=> 53: int(-1) 54: } 55: Done