Home >Backend Development >PHP Problem >How to remove the largest value from an array in php
Removal method: 1. Use the sort() function to sort the array in ascending order. The syntax is "sort($arr);". After sorting in ascending order, the last element of the array is the maximum value; 2. Use array_pop() The function deletes the last element (maximum value) of the array, the syntax is "array_pop($arr);".
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
php removes the largest array Value method
Step 1. Use sort() to sort the array in ascending order
<?php header('content-type:text/html;charset=utf-8'); $arr=array(1,45,9,52,0,-5,21,-1,40); var_dump($arr); sort($arr); var_dump($arr); ?>
Sort The last element of the array is the maximum value, just delete the element.
Step 2. Use array_pop() to remove the maximum value
array_pop(): Delete the last element in the array.
array_pop($arr); //去掉最大值 var_dump($arr);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove the largest value from an array in php. For more information, please follow other related articles on the PHP Chinese website!