How to Use the PHP array_values() Function

09/08/2021
Contents
In this article, you will learn how to use the PHP array_values() function.
PHP array_values() Function
The array_values() function in PHP takes an array as an argument and returns an array containing all the values of the input array, re-indexed numerically starting from 0.
Syntax:
array_values(array $array)
Parameters:
$array
: The input array whose values you want to extract.
Example:
Here’s an example of using array_values() to extract values from an associative array:
<?php
$fruits = array("a" => "apple", "b" => "banana", "c" => "cherry");
$values = array_values($fruits);
print_r($values);
?>
Output:
Array ( [0] => apple [1] => banana [2] => cherry )