blob: 6bcac4eedd5f0a3ddc29f060229ca370d71aa237 (
plain)
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
|
--TEST--
Test array_filter() function : usage variations - Different types of 'callback' function
--FILE--
<?php
/*
* Passing different types of callback functions to array_filter()
* with parameters and return
* without parameter and with return
* with parameter and without return
* without parameter and without return
*/
echo "*** Testing array_filter() : usage variation - different 'callback' functions***\n";
// Initialize variables
$input = array(0, -1, 2, 3.4E-3, 'hello', "value", "key" => 4, 'null' => NULL);
function callback1()
{
return 1;
}
echo "-- Callback function without parameter and with return --\n";
var_dump( array_filter($input, "callback1") );
// callback function with parameter and without return value
function callback2($input)
{
}
echo "-- Callback function with parameter and without return --\n";
var_dump( array_filter($input, "callback2") );
function callback3()
{
}
echo "-- Callback function without parameter and return --\n";
var_dump( array_filter($input, "callback3") );
// callback function with parameter and with return value
function callback4($input)
{
if($input > 0 ) {
return true;
}
else {
return false;
}
}
echo "-- Callback function with parameter and return --\n";
var_dump( array_filter($input, "callback4") );
echo "Done"
?>
--EXPECT--
*** Testing array_filter() : usage variation - different 'callback' functions***
-- Callback function without parameter and with return --
array(8) {
[0]=>
int(0)
[1]=>
int(-1)
[2]=>
int(2)
[3]=>
float(0.0034)
[4]=>
string(5) "hello"
[5]=>
string(5) "value"
["key"]=>
int(4)
["null"]=>
NULL
}
-- Callback function with parameter and without return --
array(0) {
}
-- Callback function without parameter and return --
array(0) {
}
-- Callback function with parameter and return --
array(5) {
[2]=>
int(2)
[3]=>
float(0.0034)
[4]=>
string(5) "hello"
[5]=>
string(5) "value"
["key"]=>
int(4)
}
Done
|