DEV Community

Cover image for PHP array_values
PHP Error Code
PHP Error Code

Posted on

PHP array_values

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>";

?>
Enter fullscreen mode Exit fullscreen mode

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

Suggested Articles

Top comments (0)