PHP array_values()
Published Oct 7, 2023
Contribute to Docs
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
0and 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:
Contribute to Docs
- 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.
Learn PHP on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours