1--TEST--
2Test 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
16echo "*** 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
23echo "-- Testing uasort() with built-in 'cmp_function': strcasecmp() --\n";
24var_dump( uasort($builtin_fun_arg, 'strcasecmp') );  // expecting: bool(true)
25var_dump($builtin_fun_arg);
26
27echo "-- Testing uasort() with built-in 'cmp_function': strcmp() --\n";
28var_dump( uasort($array_arg, 'strcmp') );  // expecting: bool(true)
29var_dump($array_arg);
30
31// Testing with language construct as comparison function
32echo "-- Testing uasort() with language construct as 'cmp_function' --\n";
33var_dump( uasort($languageConstruct_fun_arg, 'echo') );  // expecting: bool(false)
34
35echo "-- Testing uasort() with language construct as 'cmp_function' --\n";
36var_dump( uasort($languageConstruct_fun_arg, 'exit') );  // expecting: bool(false)
37
38echo "Done"
39?>
40--EXPECTF--
41*** Testing uasort() : built in function as 'cmp_function' ***
42-- Testing uasort() with built-in 'cmp_function': strcasecmp() --
43bool(true)
44array(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() --
57bool(true)
58array(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
72Warning: uasort() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d
73NULL
74-- Testing uasort() with language construct as 'cmp_function' --
75
76Warning: uasort() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d
77NULL
78Done
79