File: arsort_variation11.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (153 lines) | stat: -rw-r--r-- 3,101 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--TEST--
Test arsort() function : usage variations - sort mixed values, 'sort_flags' as default/SORT_REGULAR (OK to fail as result is unpredectable)
--FILE--
<?php
/*
 * testing arsort() by providing mixed value array for $array argument with following flag values.
 * 1.flag value as default
 * 2.SORT_REGULAR - compare items normally
*/

echo "*** Testing arsort() : usage variations ***\n";

// mixed value array with different key values
$mixed_values = array (
  "array1" => array(),
  "array2" => array ( "sub_array[2,1]" => array(33,-5,6), "sub_array[2,2]" => array(11),
                      "sub_array[2,3]" => array(22,-55), "sub_array[2,4]" => array()
                    ),
  4 => 4, "4" => "4", 4 => 4.01, "b" => "b", "5" => "5", -2 => -2, -2 => -2.01,
  -2 => -2.98989, "-.9" => "-.9", "True" => "True", "" =>  "", NULL => NULL,
  "ab" => "ab", "abcd" => "abcd", 0 => 0.01, -0 => -0, '' => '' ,
  "abcd\x00abcd\x00abcd" => "abcd\x00abcd\x00abcd", 0 => 0.001
);

echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is default --\n";
$temp_array = $mixed_values;
var_dump( arsort($temp_array) );
var_dump($temp_array);

echo "\n-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --\n";
$temp_array = $mixed_values;
var_dump( arsort($temp_array, SORT_REGULAR) );
var_dump($temp_array);

echo "Done\n";
?>
--EXPECTF--
*** Testing arsort() : usage variations ***

-- Testing arsort() by supplying mixed value array, 'flag' value is default --
bool(true)
array(13) {
  ["array2"]=>
  array(4) {
    ["sub_array[2,1]"]=>
    array(3) {
      [0]=>
      int(33)
      [1]=>
      int(-5)
      [2]=>
      int(6)
    }
    ["sub_array[2,2]"]=>
    array(1) {
      [0]=>
      int(11)
    }
    ["sub_array[2,3]"]=>
    array(2) {
      [0]=>
      int(22)
      [1]=>
      int(-55)
    }
    ["sub_array[2,4]"]=>
    array(0) {
    }
  }
  ["array1"]=>
  array(0) {
  }
  ["b"]=>
  string(1) "b"
  ["abcd%0abcd%0abcd"]=>
  string(14) "abcd%0abcd%0abcd"
  ["abcd"]=>
  string(4) "abcd"
  ["ab"]=>
  string(2) "ab"
  ["True"]=>
  string(4) "True"
  [5]=>
  string(1) "5"
  [4]=>
  float(4.01)
  [0]=>
  float(0.001)
  ["-.9"]=>
  string(3) "-.9"
  [-2]=>
  float(-2.98989)
  [""]=>
  string(0) ""
}

-- Testing arsort() by supplying mixed value array, 'flag' value is SORT_REGULAR --
bool(true)
array(13) {
  ["array2"]=>
  array(4) {
    ["sub_array[2,1]"]=>
    array(3) {
      [0]=>
      int(33)
      [1]=>
      int(-5)
      [2]=>
      int(6)
    }
    ["sub_array[2,2]"]=>
    array(1) {
      [0]=>
      int(11)
    }
    ["sub_array[2,3]"]=>
    array(2) {
      [0]=>
      int(22)
      [1]=>
      int(-55)
    }
    ["sub_array[2,4]"]=>
    array(0) {
    }
  }
  ["array1"]=>
  array(0) {
  }
  ["b"]=>
  string(1) "b"
  ["abcd%0abcd%0abcd"]=>
  string(14) "abcd%0abcd%0abcd"
  ["abcd"]=>
  string(4) "abcd"
  ["ab"]=>
  string(2) "ab"
  ["True"]=>
  string(4) "True"
  [5]=>
  string(1) "5"
  [4]=>
  float(4.01)
  [0]=>
  float(0.001)
  ["-.9"]=>
  string(3) "-.9"
  [-2]=>
  float(-2.98989)
  [""]=>
  string(0) ""
}
Done