xref: /PHP-7.2/ext/standard/tests/array/range.phpt (revision 17ccbeec)
1--TEST--
2Test range() function
3--INI--
4precision=14
5--FILE--
6<?php
7
8echo "*** Testing range() function on basic operations ***\n";
9
10echo "\n-- Integers as Low and High --\n";
11echo "-- An array of elements from low to high --\n";
12var_dump( range(1, 10) );
13echo "\n-- An array of elements from high to low --\n";
14var_dump( range(10, 1) );
15
16echo "\n-- Numeric Strings as Low and High --\n";
17echo "-- An array of elements from low to high --\n";
18var_dump( range("1", "10") );
19echo "\n-- An array of elements from high to low --\n";
20var_dump( range("10", "1") );
21
22echo "\n-- Chars as Low and High --\n";
23echo "-- An array of elements from low to high --\n";
24var_dump( range("a", "z") );
25echo "\n-- An array of elements from high to low --\n";
26var_dump( range("z", "a") );
27
28echo "\n-- Low and High are equal --\n";
29var_dump( range(5, 5) );
30var_dump( range("q", "q") );
31
32echo "\n-- floats as Low and High --\n";
33var_dump( range(5.1, 10.1) );
34var_dump( range(10.1, 5.1) );
35
36var_dump( range("5.1", "10.1") );
37var_dump( range("10.1", "5.1") );
38
39echo "\n-- Passing step with Low and High --\n";
40var_dump( range(1, 2, 0.1) );
41var_dump( range(2, 1, 0.1) );
42
43var_dump( range(1, 2, "0.1") );
44var_dump( range("1", "2", 0.1) );
45
46echo "\n-- Testing basic string with step --\n";
47var_dump( range("abcd", "mnop", 2) );
48
49echo "Done\n";
50?>
51--EXPECTF--
52*** Testing range() function on basic operations ***
53
54-- Integers as Low and High --
55-- An array of elements from low to high --
56array(10) {
57  [0]=>
58  int(1)
59  [1]=>
60  int(2)
61  [2]=>
62  int(3)
63  [3]=>
64  int(4)
65  [4]=>
66  int(5)
67  [5]=>
68  int(6)
69  [6]=>
70  int(7)
71  [7]=>
72  int(8)
73  [8]=>
74  int(9)
75  [9]=>
76  int(10)
77}
78
79-- An array of elements from high to low --
80array(10) {
81  [0]=>
82  int(10)
83  [1]=>
84  int(9)
85  [2]=>
86  int(8)
87  [3]=>
88  int(7)
89  [4]=>
90  int(6)
91  [5]=>
92  int(5)
93  [6]=>
94  int(4)
95  [7]=>
96  int(3)
97  [8]=>
98  int(2)
99  [9]=>
100  int(1)
101}
102
103-- Numeric Strings as Low and High --
104-- An array of elements from low to high --
105array(10) {
106  [0]=>
107  int(1)
108  [1]=>
109  int(2)
110  [2]=>
111  int(3)
112  [3]=>
113  int(4)
114  [4]=>
115  int(5)
116  [5]=>
117  int(6)
118  [6]=>
119  int(7)
120  [7]=>
121  int(8)
122  [8]=>
123  int(9)
124  [9]=>
125  int(10)
126}
127
128-- An array of elements from high to low --
129array(10) {
130  [0]=>
131  int(10)
132  [1]=>
133  int(9)
134  [2]=>
135  int(8)
136  [3]=>
137  int(7)
138  [4]=>
139  int(6)
140  [5]=>
141  int(5)
142  [6]=>
143  int(4)
144  [7]=>
145  int(3)
146  [8]=>
147  int(2)
148  [9]=>
149  int(1)
150}
151
152-- Chars as Low and High --
153-- An array of elements from low to high --
154array(26) {
155  [0]=>
156  string(1) "a"
157  [1]=>
158  string(1) "b"
159  [2]=>
160  string(1) "c"
161  [3]=>
162  string(1) "d"
163  [4]=>
164  string(1) "e"
165  [5]=>
166  string(1) "f"
167  [6]=>
168  string(1) "g"
169  [7]=>
170  string(1) "h"
171  [8]=>
172  string(1) "i"
173  [9]=>
174  string(1) "j"
175  [10]=>
176  string(1) "k"
177  [11]=>
178  string(1) "l"
179  [12]=>
180  string(1) "m"
181  [13]=>
182  string(1) "n"
183  [14]=>
184  string(1) "o"
185  [15]=>
186  string(1) "p"
187  [16]=>
188  string(1) "q"
189  [17]=>
190  string(1) "r"
191  [18]=>
192  string(1) "s"
193  [19]=>
194  string(1) "t"
195  [20]=>
196  string(1) "u"
197  [21]=>
198  string(1) "v"
199  [22]=>
200  string(1) "w"
201  [23]=>
202  string(1) "x"
203  [24]=>
204  string(1) "y"
205  [25]=>
206  string(1) "z"
207}
208
209-- An array of elements from high to low --
210array(26) {
211  [0]=>
212  string(1) "z"
213  [1]=>
214  string(1) "y"
215  [2]=>
216  string(1) "x"
217  [3]=>
218  string(1) "w"
219  [4]=>
220  string(1) "v"
221  [5]=>
222  string(1) "u"
223  [6]=>
224  string(1) "t"
225  [7]=>
226  string(1) "s"
227  [8]=>
228  string(1) "r"
229  [9]=>
230  string(1) "q"
231  [10]=>
232  string(1) "p"
233  [11]=>
234  string(1) "o"
235  [12]=>
236  string(1) "n"
237  [13]=>
238  string(1) "m"
239  [14]=>
240  string(1) "l"
241  [15]=>
242  string(1) "k"
243  [16]=>
244  string(1) "j"
245  [17]=>
246  string(1) "i"
247  [18]=>
248  string(1) "h"
249  [19]=>
250  string(1) "g"
251  [20]=>
252  string(1) "f"
253  [21]=>
254  string(1) "e"
255  [22]=>
256  string(1) "d"
257  [23]=>
258  string(1) "c"
259  [24]=>
260  string(1) "b"
261  [25]=>
262  string(1) "a"
263}
264
265-- Low and High are equal --
266array(1) {
267  [0]=>
268  int(5)
269}
270array(1) {
271  [0]=>
272  string(1) "q"
273}
274
275-- floats as Low and High --
276array(6) {
277  [0]=>
278  float(5.1)
279  [1]=>
280  float(6.1)
281  [2]=>
282  float(7.1)
283  [3]=>
284  float(8.1)
285  [4]=>
286  float(9.1)
287  [5]=>
288  float(10.1)
289}
290array(6) {
291  [0]=>
292  float(10.1)
293  [1]=>
294  float(9.1)
295  [2]=>
296  float(8.1)
297  [3]=>
298  float(7.1)
299  [4]=>
300  float(6.1)
301  [5]=>
302  float(5.1)
303}
304array(6) {
305  [0]=>
306  float(5.1)
307  [1]=>
308  float(6.1)
309  [2]=>
310  float(7.1)
311  [3]=>
312  float(8.1)
313  [4]=>
314  float(9.1)
315  [5]=>
316  float(10.1)
317}
318array(6) {
319  [0]=>
320  float(10.1)
321  [1]=>
322  float(9.1)
323  [2]=>
324  float(8.1)
325  [3]=>
326  float(7.1)
327  [4]=>
328  float(6.1)
329  [5]=>
330  float(5.1)
331}
332
333-- Passing step with Low and High --
334array(11) {
335  [0]=>
336  float(1)
337  [1]=>
338  float(1.1)
339  [2]=>
340  float(1.2)
341  [3]=>
342  float(1.3)
343  [4]=>
344  float(1.4)
345  [5]=>
346  float(1.5)
347  [6]=>
348  float(1.6)
349  [7]=>
350  float(1.7)
351  [8]=>
352  float(1.8)
353  [9]=>
354  float(1.9)
355  [10]=>
356  float(2)
357}
358array(11) {
359  [0]=>
360  float(2)
361  [1]=>
362  float(1.9)
363  [2]=>
364  float(1.8)
365  [3]=>
366  float(1.7)
367  [4]=>
368  float(1.6)
369  [5]=>
370  float(1.5)
371  [6]=>
372  float(1.4)
373  [7]=>
374  float(1.3)
375  [8]=>
376  float(1.2)
377  [9]=>
378  float(1.1)
379  [10]=>
380  float(1)
381}
382array(11) {
383  [0]=>
384  float(1)
385  [1]=>
386  float(1.1)
387  [2]=>
388  float(1.2)
389  [3]=>
390  float(1.3)
391  [4]=>
392  float(1.4)
393  [5]=>
394  float(1.5)
395  [6]=>
396  float(1.6)
397  [7]=>
398  float(1.7)
399  [8]=>
400  float(1.8)
401  [9]=>
402  float(1.9)
403  [10]=>
404  float(2)
405}
406array(11) {
407  [0]=>
408  float(1)
409  [1]=>
410  float(1.1)
411  [2]=>
412  float(1.2)
413  [3]=>
414  float(1.3)
415  [4]=>
416  float(1.4)
417  [5]=>
418  float(1.5)
419  [6]=>
420  float(1.6)
421  [7]=>
422  float(1.7)
423  [8]=>
424  float(1.8)
425  [9]=>
426  float(1.9)
427  [10]=>
428  float(2)
429}
430
431-- Testing basic string with step --
432array(7) {
433  [0]=>
434  string(1) "a"
435  [1]=>
436  string(1) "c"
437  [2]=>
438  string(1) "e"
439  [3]=>
440  string(1) "g"
441  [4]=>
442  string(1) "i"
443  [5]=>
444  string(1) "k"
445  [6]=>
446  string(1) "m"
447}
448Done
449