Annotation of embedaddon/php/ext/standard/tests/array/usort_variation8.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test usort() function : usage variations - use built in functions as $cmp_function arg
3: --FILE--
4: <?php
5: /* Prototype : bool usort(array $array_arg, string $cmp_function)
6: * Description: Sort an array by values using a user-defined comparison function
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Test usort() when comparison function is:
12: * 1. a built in comparison function
13: * 2. a language construct
14: */
15:
16: echo "*** Testing usort() : usage variation ***\n";
17:
18: // Initializing variables
19: $array_arg = array("b" => "Banana", "m" => "Mango", "a" => "apple",
20: "p" => "Pineapple", "o" => "orange");
21:
22: // Testing library functions as comparison function
23: echo "\n-- Testing usort() with built-in 'cmp_function': strcasecmp() --\n";
24: $temp_array1 = $array_arg;
25: var_dump( usort($temp_array1, 'strcasecmp') );
26: var_dump($temp_array1);
27:
28: echo "\n-- Testing usort() with built-in 'cmp_function': strcmp() --\n";
29: $temp_array2 = $array_arg;
30: var_dump( usort($temp_array2, 'strcmp') );
31: var_dump($temp_array2);
32:
33: // Testing with language construct as comparison function
34: echo "\n-- Testing usort() with language construct as 'cmp_function' --\n";
35: $temp_array3 = $array_arg;
36: var_dump( usort($temp_array3, 'echo') );
37:
38: echo "\n-- Testing usort() with language construct as 'cmp_function' --\n";
39: $temp_array4 = $array_arg;
40: var_dump( usort($temp_array4, 'exit') );
41: ?>
42: ===DONE===
43: --EXPECTF--
44: *** Testing usort() : usage variation ***
45:
46: -- Testing usort() with built-in 'cmp_function': strcasecmp() --
47: bool(true)
48: array(5) {
49: [0]=>
50: string(5) "apple"
51: [1]=>
52: string(6) "Banana"
53: [2]=>
54: string(5) "Mango"
55: [3]=>
56: string(6) "orange"
57: [4]=>
58: string(9) "Pineapple"
59: }
60:
61: -- Testing usort() with built-in 'cmp_function': strcmp() --
62: bool(true)
63: array(5) {
64: [0]=>
65: string(6) "Banana"
66: [1]=>
67: string(5) "Mango"
68: [2]=>
69: string(9) "Pineapple"
70: [3]=>
71: string(5) "apple"
72: [4]=>
73: string(6) "orange"
74: }
75:
76: -- Testing usort() with language construct as 'cmp_function' --
77:
78: Warning: usort() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d
79: NULL
80:
81: -- Testing usort() with language construct as 'cmp_function' --
82:
83: Warning: usort() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d
84: NULL
85: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>