Home > Article > Backend Development > How to flip an array in php and get the minimum value
Implementation method: 1. Use the array_reverse() function to reverse the array. The syntax "array_reverse($array)" will reverse the order of elements in the original array, create a new array and return it; 2. Use min The () function takes out the minimum value of the flipped array, the syntax is "min (flip array)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php flips an array And take out the minimum value method:
Implementation method:
First you need to flip the array, PHP has built-in such function The function--array_reverse() function
array_reverse() function will reverse the order of elements in the original array, create a new array and return
# and then take out the flipped array The minimum value, PHP also has a built-in function with this function--min() function
min() function returns the minimum value in an array
Implementation code:
<?php header('content-type:text/html;charset=utf-8'); $array = array(4,2,3,5,2,0,6); echo "原数组:"; var_dump($array); echo "翻转后的数组:"; $reverse=array_reverse($array); var_dump($reverse); echo "最小值:".min($reverse); ?>
Description: array_reverse() function
array_reverse() function returns an array in reverse order.
array_reverse(array,preserve)
Parameters | Description |
---|---|
array | Required . Specifies an array. |
preserve | Optional. Specifies whether to retain the original array key names. If set to TRUE, numeric keys will be preserved. Non-numeric keys are not affected by this setting and will always be retained. Possible values:
|
<?php $a=array("Volvo","XC90",array("BMW","Toyota")); $preserve=array_reverse($a,true); var_dump($preserve); ?>Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of How to flip an array in php and get the minimum value. For more information, please follow other related articles on the PHP Chinese website!