It is an in-built function in PHP that is used to show element values of a given array in a new array. PHP array_values function creates a new array in which it stores only values of elements from a given array and by default gives the numerical keys to every single value.
Example
<?php
$arr=array("Name"=>"warner","Age"=>"24","Country"=>"USA");
echo "<pre>";
print_r(array_values($arr));
echo "</pre>";
?>
Output
Array
(
[0] => Ali
[1] => 20
[2] => Pakistan
)
Now you can see a new array has been created and only values are showing in it.
Conclusion
In this tutorial, we learned about the array_values function, see the definition, and then discuss a example. You can also learn
Top comments (0)