PHP | array_values() Function
This inbuilt function in PHP 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.
Syntax:
array array_values($array)
Parameters: This function takes only one parameter $array which is mandatory and refers to the original input array, from which values needs to be fetched.
Return Value: This function returns an array with the fetched values, indexed with the numerical keys.
Examples:
Input : $array = ("ram"=>25, "krishna"=>10, "aakash"=>20, "gaurav")
Output :
Array
(
[0] => 25
[1] => 10
[2] => 20
[3] => gaurav
)
Input : $array = ("ram", "krishna", "aakash", "gaurav")
Output :
Array
(
[0] => ram
[1] => krishna
[2] => aakash
[3] => gaurav
)
Below program illustrates the array_values() function in PHP:
// PHP function to illustrate the use of array_values() function Return_Values($array) { return (array_values($array)); } $array = array("ram"=>25, "krishna"=>10, "aakash"=>20, "gaurav"); print_r(Return_Values($array)); ?> |
Output:
Array
(
[0] => 25
[1] => 10
[2] => 20
[3] => gaurav
)
Reference:
http://php.net/manual/en/function.array-values.php
Recommended Posts:
- PHP | cos( ) Function
- PHP | tan( ) Function
- PHP | key() Function
- PHP | each() Function
- PHP | next() Function
- PHP Ds\Map sum() Function
- PHP | sin( ) Function
- PHP | pi( ) Function
- PHP | min( ) Function
- PHP | max( ) Function
- PHP Ds\Map first() Function
- PHP | Ds\Set last() Function
- PHP | ord() Function
- PHP | Ds\Set add() Function
- PHP | Ds\Set first() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



