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