PHP array_values() Function
In this article, we will see how to get an array value using the array_values() function in PHP, along with understanding their implementation through the example.
The array_values() is an inbuilt PHP function is used to get an array of values from another array that may contain key-value pairs or just values. The function creates another array where it stores all the values and by default assigns numerical keys to the values.
Parameters: This function takes only one parameter $array which is mandatory and refers to the original input array, from which values need to be fetched.
Return Value: This function returns an array with the fetched values, indexed with the numerical keys.
Consider the following examples. Here, we are using the concept of Associative arrays that are used to store key-value pairs.
Input: $array = ("ram"=>25, "krishna"=>10, "aakash"=>20, "gaurav") Output: Array (  => 25  => 10  => 20  => gaurav ) Explanation: This array use named keys that we have assigned to them. For those array element that has not assigned any value, will display their index value. Input: $array = ("ram", "krishna", "aakash", "gaurav") Output: Array (  => ram  => krishna  => aakash  => gaurav ) Explanation: This array displays the array item along with index value.
Example: The below example illustrates the array_values() function in PHP.
Array (  => 25  => 10  => 20  => gaurav )