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 0 and increase by 1.

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:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy