array_values()
The array_values()
function returns all the values from an array in numerical order.
Syntax
array_values(array)
Note: The array that is returned will have numeric keys that start from
0
and increase by1
.
Example
The example shown below creates an array called $vehicle
with three key-value pairs. It then uses the array_values()
function to extract the array’s values.
<?php$vehicle = array("car" => "BMW", "color" => "gold", "model" => "X5");print_r(array_values($vehicle));?>
This results in the following output printed to the console.
Array([0] => BMW[1] => gold[2] => X5)
Codebyte Example
This code example is runnable and demonstrates how values can be returned using the array_values()
function:
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.