1
0
mirror of https://github.com/php/php-src.git synced 2026-03-27 09:42:22 +01:00
Files
archived-php-src/ext/standard/tests/array/packed_001.phpt
Sara Golemon c74bc87c74 Minor optimizations to array_keys()/array_values()
array_values():
When the input is an empty array or a packed array with no gaps,
return the original array.

array_keys():
When the input is an empty array, return the original array.
When the input is a packed array with no holes
(and no search key specified), populate the return with
a simple range(0, count($input) - 1)
2017-03-14 11:23:02 -07:00

85 lines
773 B
PHP

--TEST--
array_keys() and array_values() w/ packed optimization
--FILE--
<?php
$x = [1,2,3];
unset($x[1]);
$inputs = [
[],
[1,2,3],
[0=>1, 1=>2, 2=>3],
[1=>1, 2=>2, 3=>3],
[0=>1, 2=>3],
$x,
];
foreach ($inputs as $input) {
print_r(array_keys($input));
print_r(array_values($input));
}
--EXPECT--
Array
(
)
Array
(
)
Array
(
[0] => 0
[1] => 1
[2] => 2
)
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 0
[1] => 1
[2] => 2
)
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Array
(
[0] => 0
[1] => 2
)
Array
(
[0] => 1
[1] => 3
)
Array
(
[0] => 0
[1] => 2
)
Array
(
[0] => 1
[1] => 3
)