1--TEST--
2Test uasort() function : usage variations - sort array with all possible keys
3--FILE--
4<?php
5/*
6* Testing uasort() with 'array_arg' having different keys
7*/
8
9echo "*** Testing uasort() : Sorting array with all possible keys ***\n";
10
11//comparison function
12function cmp_function($value1, $value2)
13{
14  if($value1 == $value2) {
15    return 0;
16  }
17  else if($value1 > $value2) {
18    return -1;
19  }
20  else {
21    return 1;
22  }
23}
24
25// different heredoc strings
26//empty heredoc string
27$empty_heredoc = <<<EOT1
28EOT1;
29
30// single line heredoc string
31$simple_heredoc = <<<EOT2
32simple
33EOT2;
34
35// multiline heredoc string
36$multiline_heredoc = <<<EOT3
37multiline heredoc with 123
38and speci@! ch@r..\ncheck\talso
39EOT3;
40
41$array_arg = array(
42  // default key
43  1,  //expecting: default key 0, value will be replaced by 'FALSE'
44
45  // numeric keys
46  1 => 10, // expecting: value will be replaced by 'TRUE'
47  -2 => 9,
48  012 => 7,
49  0x34 => 6,
50
51  // string keys
52  'key' => 5,  //single quoted key
53  "two" => 4,  //double quoted key
54  '' => 3,
55  "" => 2,
56  " " => 0,  // space as key
57
58  // bool keys
59  true => 15,
60  false => 5,
61  TRUE => 100,
62  FALSE => 25,
63
64  // null keys
65  null => 20,  // expecting: value will be replaced by 'NULL'
66  NULL => 35,
67
68  // binary key
69  "a".chr(0)."b" => 45,
70  b"binary" => 30,
71
72  //heredoc keys
73  $empty_heredoc => 90,
74  $simple_heredoc => 75,
75  $multiline_heredoc => 200,
76);
77
78var_dump( uasort($array_arg, 'cmp_function') );
79echo "-- Sorted array after uasort() function call --\n";
80var_dump($array_arg);
81
82echo "Done"
83?>
84--EXPECTF--
85*** Testing uasort() : Sorting array with all possible keys ***
86bool(true)
87-- Sorted array after uasort() function call --
88array(13) {
89  ["multiline heredoc with 123
90and speci@! ch@r..
91check	also"]=>
92  int(200)
93  [1]=>
94  int(100)
95  [""]=>
96  int(90)
97  ["simple"]=>
98  int(75)
99  ["a%0b"]=>
100  int(45)
101  ["binary"]=>
102  int(30)
103  [0]=>
104  int(25)
105  [-2]=>
106  int(9)
107  [10]=>
108  int(7)
109  [52]=>
110  int(6)
111  ["key"]=>
112  int(5)
113  ["two"]=>
114  int(4)
115  [" "]=>
116  int(0)
117}
118Done
119