php-src/ext/standard/tests/array/range.phpt

449 lines
5.6 KiB
Plaintext
Raw Normal View History

--TEST--
2007-05-16 21:10:57 +00:00
Test range() function
2007-06-28 16:05:51 +00:00
--INI--
precision=14
--FILE--
<?php
2007-05-16 21:10:57 +00:00
echo "*** Testing range() function on basic operations ***\n";
echo "\n-- Integers as Low and High --\n";
echo "-- An array of elements from low to high --\n";
var_dump( range(1, 10) );
echo "\n-- An array of elements from high to low --\n";
var_dump( range(10, 1) );
echo "\n-- Numeric Strings as Low and High --\n";
echo "-- An array of elements from low to high --\n";
var_dump( range("1", "10") );
echo "\n-- An array of elements from high to low --\n";
var_dump( range("10", "1") );
echo "\n-- Chars as Low and High --\n";
echo "-- An array of elements from low to high --\n";
var_dump( range("a", "z") );
echo "\n-- An array of elements from high to low --\n";
var_dump( range("z", "a") );
echo "\n-- Low and High are equal --\n";
var_dump( range(5, 5) );
var_dump( range("q", "q") );
echo "\n-- floats as Low and High --\n";
var_dump( range(5.1, 10.1) );
var_dump( range(10.1, 5.1) );
var_dump( range("5.1", "10.1") );
var_dump( range("10.1", "5.1") );
echo "\n-- Passing step with Low and High --\n";
var_dump( range(1, 2, 0.1) );
var_dump( range(2, 1, 0.1) );
var_dump( range(1, 2, "0.1") );
var_dump( range("1", "2", 0.1) );
echo "\n-- Testing basic string with step --\n";
var_dump( range("abcd", "mnop", 2) );
2007-06-28 16:05:51 +00:00
echo "Done\n";
?>
--EXPECT--
2007-06-28 16:05:51 +00:00
*** Testing range() function on basic operations ***
2007-05-16 21:10:57 +00:00
2007-06-28 16:05:51 +00:00
-- Integers as Low and High --
-- An array of elements from low to high --
array(10) {
2007-05-16 21:10:57 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
int(1)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
int(2)
2007-05-16 21:10:57 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
int(3)
2007-05-16 21:10:57 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
int(4)
2007-05-16 21:10:57 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
int(5)
2007-05-16 21:10:57 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
int(6)
2007-05-16 21:10:57 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
int(7)
2005-08-17 15:12:03 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
int(8)
2005-08-17 15:12:03 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
int(9)
2005-08-17 15:12:03 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
int(10)
2007-05-16 21:10:57 +00:00
}
2007-06-28 16:05:51 +00:00
-- An array of elements from high to low --
array(10) {
2007-05-16 21:10:57 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
int(10)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
int(9)
2005-08-17 15:12:03 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
int(8)
2005-08-17 15:12:03 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
int(7)
2005-08-17 15:12:03 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
int(6)
2005-08-17 15:12:03 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
int(5)
2005-08-17 15:12:03 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
int(4)
2005-08-17 15:12:03 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
int(3)
2005-08-17 15:12:03 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
int(2)
2005-08-17 15:12:03 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
int(1)
2007-05-16 21:10:57 +00:00
}
2007-06-28 16:05:51 +00:00
-- Numeric Strings as Low and High --
-- An array of elements from low to high --
array(10) {
2007-05-16 21:10:57 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
int(1)
2005-08-17 15:12:03 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
int(2)
2005-08-17 15:12:03 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
int(3)
2005-08-17 15:12:03 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
int(4)
2005-08-17 15:12:03 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
int(5)
2005-08-17 15:12:03 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
int(6)
2005-08-17 15:12:03 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
int(7)
2005-08-17 15:12:03 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
int(8)
2005-08-17 15:12:03 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
int(9)
2005-08-17 15:12:03 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
int(10)
2007-05-16 21:10:57 +00:00
}
2007-06-28 16:05:51 +00:00
-- An array of elements from high to low --
array(10) {
2007-05-16 21:10:57 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
int(10)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
int(9)
2005-08-17 15:12:03 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
int(8)
2005-08-17 15:12:03 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
int(7)
2005-08-17 15:12:03 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
int(6)
2005-08-17 15:12:03 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
int(5)
2005-08-17 15:12:03 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
int(4)
2005-08-17 15:12:03 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
int(3)
2005-08-17 15:12:03 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
int(2)
2005-08-17 15:12:03 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
int(1)
2005-08-17 15:12:03 +00:00
}
2007-05-16 21:10:57 +00:00
2007-06-28 16:05:51 +00:00
-- Chars as Low and High --
-- An array of elements from low to high --
array(26) {
2005-08-17 15:12:03 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
unicode(1) "a"
2005-08-17 15:12:03 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
unicode(1) "b"
2005-08-17 15:12:03 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
unicode(1) "c"
2005-08-17 15:12:03 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
unicode(1) "d"
2005-08-17 15:12:03 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
unicode(1) "e"
2005-08-17 15:12:03 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
unicode(1) "f"
2005-08-17 15:12:03 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
unicode(1) "g"
2005-08-17 15:12:03 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
unicode(1) "h"
2005-08-17 15:12:03 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
unicode(1) "i"
2005-08-17 15:12:03 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
unicode(1) "j"
2005-08-17 15:12:03 +00:00
[10]=>
2007-06-28 16:05:51 +00:00
unicode(1) "k"
[11]=>
unicode(1) "l"
[12]=>
unicode(1) "m"
[13]=>
unicode(1) "n"
[14]=>
unicode(1) "o"
[15]=>
unicode(1) "p"
[16]=>
unicode(1) "q"
[17]=>
unicode(1) "r"
[18]=>
unicode(1) "s"
[19]=>
unicode(1) "t"
[20]=>
unicode(1) "u"
[21]=>
unicode(1) "v"
[22]=>
unicode(1) "w"
[23]=>
unicode(1) "x"
[24]=>
unicode(1) "y"
[25]=>
unicode(1) "z"
2005-08-17 15:12:03 +00:00
}
2007-05-16 21:10:57 +00:00
2007-06-28 16:05:51 +00:00
-- An array of elements from high to low --
array(26) {
2005-08-17 15:12:03 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
unicode(1) "z"
2005-08-17 15:12:03 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
unicode(1) "y"
2005-08-17 15:12:03 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
unicode(1) "x"
2005-08-17 15:12:03 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
unicode(1) "w"
2005-08-17 15:12:03 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
unicode(1) "v"
2005-08-17 15:12:03 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
unicode(1) "u"
2005-08-17 15:12:03 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
unicode(1) "t"
2005-08-17 15:12:03 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
unicode(1) "s"
2005-08-17 15:12:03 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
unicode(1) "r"
2005-08-17 15:12:03 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
unicode(1) "q"
2005-08-17 15:12:03 +00:00
[10]=>
2007-06-28 16:05:51 +00:00
unicode(1) "p"
[11]=>
unicode(1) "o"
[12]=>
unicode(1) "n"
[13]=>
unicode(1) "m"
[14]=>
unicode(1) "l"
[15]=>
unicode(1) "k"
[16]=>
unicode(1) "j"
[17]=>
unicode(1) "i"
[18]=>
unicode(1) "h"
[19]=>
unicode(1) "g"
[20]=>
unicode(1) "f"
[21]=>
unicode(1) "e"
[22]=>
unicode(1) "d"
[23]=>
unicode(1) "c"
[24]=>
unicode(1) "b"
[25]=>
unicode(1) "a"
2005-08-17 15:12:03 +00:00
}
2007-05-16 21:10:57 +00:00
2007-06-28 16:05:51 +00:00
-- Low and High are equal --
array(1) {
[0]=>
int(5)
}
array(1) {
[0]=>
unicode(1) "q"
}
2007-05-16 21:10:57 +00:00
2007-06-28 16:05:51 +00:00
-- floats as Low and High --
array(6) {
[0]=>
2007-06-28 16:05:51 +00:00
float(5.1)
[1]=>
2007-06-28 16:05:51 +00:00
float(6.1)
[2]=>
2007-06-28 16:05:51 +00:00
float(7.1)
[3]=>
2007-06-28 16:05:51 +00:00
float(8.1)
[4]=>
2007-06-28 16:05:51 +00:00
float(9.1)
[5]=>
2007-06-28 16:05:51 +00:00
float(10.1)
}
2007-06-28 16:05:51 +00:00
array(6) {
[0]=>
2007-06-28 16:05:51 +00:00
float(10.1)
[1]=>
2007-06-28 16:05:51 +00:00
float(9.1)
[2]=>
float(8.1)
[3]=>
float(7.1)
[4]=>
float(6.1)
[5]=>
float(5.1)
}
2007-06-28 16:05:51 +00:00
array(6) {
[0]=>
2007-06-28 16:05:51 +00:00
float(5.1)
[1]=>
2007-06-28 16:05:51 +00:00
float(6.1)
[2]=>
2007-06-28 16:05:51 +00:00
float(7.1)
[3]=>
2007-06-28 16:05:51 +00:00
float(8.1)
[4]=>
2007-06-28 16:05:51 +00:00
float(9.1)
[5]=>
2007-06-28 16:05:51 +00:00
float(10.1)
2007-05-16 21:10:57 +00:00
}
2007-06-28 16:05:51 +00:00
array(6) {
2007-05-16 21:10:57 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
float(10.1)
[1]=>
2007-06-28 16:05:51 +00:00
float(9.1)
[2]=>
float(8.1)
[3]=>
float(7.1)
[4]=>
float(6.1)
[5]=>
float(5.1)
2007-05-16 21:10:57 +00:00
}
2007-06-28 16:05:51 +00:00
-- Passing step with Low and High --
2007-05-16 21:10:57 +00:00
array(11) {
[0]=>
2007-06-28 16:05:51 +00:00
float(1)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
float(1.1)
[2]=>
2007-06-28 16:05:51 +00:00
float(1.2)
[3]=>
2007-06-28 16:05:51 +00:00
float(1.3)
[4]=>
2007-06-28 16:05:51 +00:00
float(1.4)
[5]=>
2007-06-28 16:05:51 +00:00
float(1.5)
[6]=>
2007-06-28 16:05:51 +00:00
float(1.6)
[7]=>
2007-06-28 16:05:51 +00:00
float(1.7)
[8]=>
2007-06-28 16:05:51 +00:00
float(1.8)
[9]=>
2007-06-28 16:05:51 +00:00
float(1.9)
[10]=>
2007-06-28 16:05:51 +00:00
float(2)
2007-05-16 21:10:57 +00:00
}
array(11) {
[0]=>
2007-06-28 16:05:51 +00:00
float(2)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
float(1.9)
2007-05-16 21:10:57 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
float(1.8)
2007-05-16 21:10:57 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
float(1.7)
2007-05-16 21:10:57 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
float(1.6)
2007-05-16 21:10:57 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
float(1.5)
2007-05-16 21:10:57 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
float(1.4)
2007-05-16 21:10:57 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
float(1.3)
2007-05-16 21:10:57 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
float(1.2)
2007-05-16 21:10:57 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
float(1.1)
2007-05-16 21:10:57 +00:00
[10]=>
2007-06-28 16:05:51 +00:00
float(1)
2007-05-16 21:10:57 +00:00
}
array(11) {
[0]=>
2007-06-28 16:05:51 +00:00
float(1)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
float(1.1)
2007-05-16 21:10:57 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
float(1.2)
2007-05-16 21:10:57 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
float(1.3)
2007-05-16 21:10:57 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
float(1.4)
2007-05-16 21:10:57 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
float(1.5)
2007-05-16 21:10:57 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
float(1.6)
2007-05-16 21:10:57 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
float(1.7)
2007-05-16 21:10:57 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
float(1.8)
2007-05-16 21:10:57 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
float(1.9)
2007-05-16 21:10:57 +00:00
[10]=>
2007-06-28 16:05:51 +00:00
float(2)
2007-05-16 21:10:57 +00:00
}
array(11) {
[0]=>
2007-06-28 16:05:51 +00:00
float(1)
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
float(1.1)
2007-05-16 21:10:57 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
float(1.2)
2007-05-16 21:10:57 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
float(1.3)
2007-05-16 21:10:57 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
float(1.4)
2007-05-16 21:10:57 +00:00
[5]=>
2007-06-28 16:05:51 +00:00
float(1.5)
2007-05-16 21:10:57 +00:00
[6]=>
2007-06-28 16:05:51 +00:00
float(1.6)
2007-05-16 21:10:57 +00:00
[7]=>
2007-06-28 16:05:51 +00:00
float(1.7)
2007-05-16 21:10:57 +00:00
[8]=>
2007-06-28 16:05:51 +00:00
float(1.8)
2007-05-16 21:10:57 +00:00
[9]=>
2007-06-28 16:05:51 +00:00
float(1.9)
2007-05-16 21:10:57 +00:00
[10]=>
2007-06-28 16:05:51 +00:00
float(2)
2007-05-16 21:10:57 +00:00
}
2007-06-28 16:05:51 +00:00
-- Testing basic string with step --
array(7) {
2007-05-16 21:10:57 +00:00
[0]=>
2007-06-28 16:05:51 +00:00
unicode(1) "a"
2007-05-16 21:10:57 +00:00
[1]=>
2007-06-28 16:05:51 +00:00
unicode(1) "c"
2007-05-16 21:10:57 +00:00
[2]=>
2007-06-28 16:05:51 +00:00
unicode(1) "e"
2007-05-16 21:10:57 +00:00
[3]=>
2007-06-28 16:05:51 +00:00
unicode(1) "g"
2007-05-16 21:10:57 +00:00
[4]=>
2007-06-28 16:05:51 +00:00
unicode(1) "i"
[5]=>
unicode(1) "k"
[6]=>
unicode(1) "m"
2007-05-16 21:10:57 +00:00
}
Done