Home >>PHP Array Functions >PHP array_values() Function

PHP array_values() Function

PHP array_values() Function

PHP array_values() function is used to create an array of values only from another given array that may contain key-value pairs or values only. It creates another array where it stores all the values of the given array elements and by default assigns a numerical key to the values. It accepts only a single parameter $array which is the original input array.

Syntax:

array_values($array);

Parameter Values

Parameter Description
array This is a required parameter. This parameter defines the given array.

Here is an example of array_values() function in PHP:

<html>
<body>
<pre>
<?php
$x=array("Name"=>"Jerry","Age"=>"21","Work"=>"Developer","Place"=>"Noida","Country"=>"India");
print_r(array_values($x));
?>
</pre>
</body>
</html>
Output:
Array
(
    [0] => Jerry
    [1] => 21
    [2] => Developer
    [3] => Noida
    [4] => India
)

Example 2:

<html>
<body>
<pre>
<?php
$x=array("Name"=>"Jerry","Developer","Place"=>"Noida","Country"=>"India","ASUS","PHPTPOINT","Company"=>"Google");
print_r(array_values($x));
?>
</pre>
</body>
</html>
Output:
Array
(
    [0] => Jerry
    [1] => Developer
    [2] => Noida
    [3] => India
    [4] => ASUS
    [5] => PHPTPOINT
    [6] => Google
)

No Sidebar ads