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