Return to array_filter_variation5.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 : usage variations - 'input' argument with different false entries 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: * With default callback function argument, array_filter() removes elements which are interpreted as false 12: * Here Testing all the false array element possibilities 13: */ 14: 15: // callback function always_true 16: function always_true($input) 17: { 18: return true; 19: } 20: 21: // callback function always_false 22: function always_false($input) 23: { 24: return false; 25: } 26: 27: echo "*** Testing array_filter() : usage variations - different false elements in 'input' ***\n"; 28: 29: // unset variable 30: $unset_var = 10; 31: unset($unset_var); 32: 33: // empty heredoc string 34: $empty_heredoc =<<<EOT 35: EOT; 36: 37: // input array with different false elements 38: $input = array( 39: false, 40: False, 41: '', 42: "", 43: 0, 44: 0.0, 45: null, 46: NULL, 47: "0", 48: '0', 49: array(), 50: !1, 51: 1==2, 52: $empty_heredoc, 53: @$unset_var, 54: @$undefined_var, 55: ); 56: 57: // With default callback function 58: var_dump( array_filter($input) ); 59: 60: // With callback function which returns always true 61: var_dump( array_filter($input, 'always_true') ); 62: 63: // With callback function which returns always false 64: var_dump( array_filter($input, 'always_false') ); 65: 66: echo "Done" 67: ?> 68: --EXPECTF-- 69: *** Testing array_filter() : usage variations - different false elements in 'input' *** 70: array(0) { 71: } 72: array(16) { 73: [0]=> 74: bool(false) 75: [1]=> 76: bool(false) 77: [2]=> 78: string(0) "" 79: [3]=> 80: string(0) "" 81: [4]=> 82: int(0) 83: [5]=> 84: float(0) 85: [6]=> 86: NULL 87: [7]=> 88: NULL 89: [8]=> 90: string(1) "0" 91: [9]=> 92: string(1) "0" 93: [10]=> 94: array(0) { 95: } 96: [11]=> 97: bool(false) 98: [12]=> 99: bool(false) 100: [13]=> 101: string(0) "" 102: [14]=> 103: NULL 104: [15]=> 105: NULL 106: } 107: array(0) { 108: } 109: Done