PHP array_values() function returns all the values from an array. This function indexes the array numerically.
array(required): It is an input array.
This method returns an array with the fetched values.
Example 1: How to Use array_values() function
<?php $arr = [ 'a' => 'Apple', 'b' => 'Microsoft', 'c' => 'Amazon', 'd' => 'Alphabet', 'e' => 'Meta']; echo 'Before array_values() function: '; print_r($arr); echo 'After array_values() function: '; print_r(array_values($arr));
Before array_values() function: Array ( [a] => Apple [b] => Microsoft [c] => Amazon [d] => Alphabet [e] => Meta ) After array_values() function: Array (  => Apple  => Microsoft  => Amazon  => Alphabet  => Meta )
In this example, the function returns an array containing the values from $arr. The output is : [‘Apple’, ‘Microsoft’, ‘Amazon’, ‘Alphabet’, ‘Meta’].
Just a warning that re-indexing an array by array_values() may cause you to reach the memory limit unexpectedly.
The array_keys() and array_values() are very closely related functions. The first function returns an array of all the keys, and the second returns all the values.
For example, consider you had an array with user IDs as keys and usernames as values; you could use array_keys() to generate an array where the values were the keys.