Some people don’t understand key values very well when it comes to some operations on arrays. In order to facilitate everyone to better return some values, this article introduces the array_values() function, which can directly return the array after use. Let’s introduce the definition, syntax, parameters, return values, and instances of the array_values() function. Let’s take a look at the method of returning an array.
1. Definition
The array_values() function returns an array containing all key values in a given array, but does not retain the key names.
2. Syntax
array_values(array)
3. Parameters
array
4. Return value
Returns an array containing all the values in the array.
5. Example
<?php $lu=''; $js= file_get_contents($lu); $okjson=json_decode($js,true); var_dump($okjson); /*array(1) { ["this"]=> array(3) { [0]=> array(2) { ["name"]=> string(1) "a" ["url"]=> string(2) "aa" } [1]=> array(2) { ["name"]=> string(1) "b" ["url"]=> string(2) "bb" } [2]=> array(2) { ["name"]=> string(1) "c" ["url"]=> string(2) "cc" } } } */ unset($okjson["this"][1]); var_dump($okjson); /* array(1) { ["this"]=> array(2) { [0]=> array(2) { ["name"]=> string(1) "a" ["url"]=> string(2) "aa" } [2]=> array(2) { ["name"]=> string(1) "c" ["url"]=> string(2) "cc" } } } */ $okjson['this'] = array_values($okjson['this']); var_dump($okjson); /* array(1) { ["this"]=> array(2) { [0]=> array(2) { ["name"]=> string(1) "a" ["url"]=> string(2) "aa" } [1]=> array(2) { ["name"]=> string(1) "c" ["url"]=> string(2) "cc" } } } */ ?>
PHP array_values() function instance extension:
Example
Returns all values of the array (non-key names):
<?php $a=array("Name"=>"Bill","Age"=>"60","Country"=>"USA"); print_r(array_values($a)); ?>
This is the article about the operation example of array_values() returning array in php. For more related array_values() returning array content in php, please search for my previous article or continue browsing the following related articles. I hope everyone will support me in the future!