In this tutorial, you shall learn about PHP array_change_key_case() function which can change the case of all keys in an array, with syntax and examples.
PHP arrayvalues Function
The PHP array_values() function returns an indexed array with all the values from given array.
In this tutorial, we will learn the syntax of array_values() and how to use it to get values from associative arrays and indexed arrays.
Syntax of arrayvalues
The syntax of array_values() function is
array_values( array )
where
Parameter | Description |
---|---|
array | [mandatory] The array from which values has to be extracted. |
Function Return Value
array_values() returns an indexed array containing all the values of array given as argument to it.
Examples
1 Get values fromm an Array
In this example, we will take an array with two key-value pairs. We will get the values alone form this array using array_values() function.
PHP Program
<?php $array1 = array("a"=>"apple", "b"=>"banana"); $values = array_values($array1); print_r($array1); echo "<br>Values array is: <br>"; print_r($values); ?>
Output
Please note that the returned array is an indexed array with index starting from 0.
2 Get Values from an Indexed Array
In this example, we will take an indexed array with two items. We will get the values alone form this array using array_values() function. The index is dropped and the values alone are picked.
PHP Program
<?php $array1 = array(7=>"apple", "banana"); $values = array_values($array1); print_r($array1); echo "<br>Values array is: <br>"; print_r($values); ?>
Output
3 Get Values from an Array with Default Index
If you provide an array with default index, then the result of array_values() function is also same as the of the given input array.
PHP Program
<?php $array1 = array("apple", "banana"); $values = array_values($array1); print_r($array1); echo "<br>Values array is: <br>"; print_r($values); ?>
Output
Conclusion
In this PHP Tutorial, we learned how to get all values in an array, using PHP Array array_values() function.