blob: fd92a9f8561ce3c51eff8d4e15e24fee3f9425f1 (
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
|
--TEST--
Test uasort() function : usage variations - anonymous function as 'cmp_function'
--FILE--
<?php
/*
* Passing different anonymous functions as 'cmp_function'
* arguments passed by value
* arguments passed by reference
*/
echo "*** Testing uasort() : anonymous function as 'cmp_function' ***\n";
$cmp_function = function($value1, $value2) {
if ($value1 == $value2) { return 0; }
else if ($value1 > $value2) { return 1; }
else { return -1; }
};
$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90);
echo "-- Anonymous 'cmp_function' with parameters passed by value --\n";
var_dump( uasort($array_arg, $cmp_function) );
var_dump($array_arg);
$cmp_function = function(&$value1, &$value2) {
if ($value1 == $value2) { return 0; }
else if ($value1 > $value2) { return 1; }
else { return -1; }
};
$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple");
echo "-- Anonymous 'cmp_function' with parameters passed by reference --\n";
var_dump( uasort($array_arg, $cmp_function ) );
var_dump($array_arg);
echo "Done"
?>
--EXPECT--
*** Testing uasort() : anonymous function as 'cmp_function' ***
-- Anonymous 'cmp_function' with parameters passed by value --
bool(true)
array(5) {
[2]=>
int(-70)
[1]=>
int(3)
[3]=>
int(24)
[4]=>
int(90)
[0]=>
int(100)
}
-- Anonymous 'cmp_function' with parameters passed by reference --
bool(true)
array(4) {
["a"]=>
string(5) "Apple"
["b"]=>
string(6) "Banana"
["m"]=>
string(5) "Mango"
["p"]=>
string(9) "Pineapple"
}
Done
|