1--TEST--
2Test 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
16echo "*** 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
23echo "\n-- Testing usort() with built-in 'cmp_function': strcasecmp() --\n";
24$temp_array1 = $array_arg;
25var_dump( usort($temp_array1, 'strcasecmp') );
26var_dump($temp_array1);
27
28echo "\n-- Testing usort() with built-in 'cmp_function': strcmp() --\n";
29$temp_array2 = $array_arg;
30var_dump( usort($temp_array2, 'strcmp') );
31var_dump($temp_array2);
32
33// Testing with language construct as comparison function
34echo "\n-- Testing usort() with language construct as 'cmp_function' --\n";
35$temp_array3 = $array_arg;
36var_dump( usort($temp_array3, 'echo') );
37
38echo "\n-- Testing usort() with language construct as 'cmp_function' --\n";
39$temp_array4 = $array_arg;
40var_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() --
47bool(true)
48array(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() --
62bool(true)
63array(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
78Warning: usort() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d
79NULL
80
81-- Testing usort() with language construct as 'cmp_function' --
82
83Warning: usort() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d
84NULL
85===DONE===
86