Home  >  Article  >  Backend Development  >  How to flip an array in php and get the minimum value

How to flip an array in php and get the minimum value

青灯夜游
青灯夜游Original
2022-05-07 13:53:461837browse

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)".

How to flip an array in php and get the minimum value

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(&#39;content-type:text/html;charset=utf-8&#39;);   
$array = array(4,2,3,5,2,0,6);
echo "原数组:";
var_dump($array);
echo "翻转后的数组:";
$reverse=array_reverse($array);
var_dump($reverse);
echo "最小值:".min($reverse);
?>

How to flip an array in php and get the minimum value

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:
  • true
  • false
##If the preserve parameter is specified as true, then The element's key name remains unchanged, otherwise the key name will be lost; the default value is false.

<?php
$a=array("Volvo","XC90",array("BMW","Toyota"));
$preserve=array_reverse($a,true);
var_dump($preserve);
?>

How to flip an array in php and get the minimum value

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn