array_values
array array_values(array array)
Returns all values from an array.
Returns:
Indexed array containing all values from another array; NULL on failure
Description:
This function simply returns an indexed array in which each element is the corresponding element from array
. The returned array is consecutively indexed starting from 0; all keys from the original array are ignored.
One use for this function is to quickly collapse an array that has had some elements unset using unset() into a freshly-ordered indexed array with no blank entries.
Version:
PHP 4
Example:
Get the values from an array
$array = array(1, 2, 3, 5, 7, 11, 13, 17, 19, 23);
unset($array[3]);
unset($array[7]);
echo "Original array:\n";
print_r($array);
$arr2 = array_values($array);
echo "New array:\n";
print_r($arr2);
Output:
Original array:
Array
(
[0] => 1
[1] => 2
[2] => 3
[4] => 7
[5] => 11
[6] => 13
[8] => 19
[9] => 23
)
New array:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 7
[4] => 11
[5] => 13
[6] => 19
[7] => 23
)
|