Home > Backend Development > PHP Problem > How to remove the largest value from an array in php

How to remove the largest value from an array in php

青灯夜游
Release: 2023-03-16 10:44:02
Original
2252 people have browsed it

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

How to remove the largest value from an array in php

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(&#39;content-type:text/html;charset=utf-8&#39;);   
$arr=array(1,45,9,52,0,-5,21,-1,40);
var_dump($arr);
sort($arr);
var_dump($arr);
?>
Copy after login

How to remove the largest value from an array in php

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);
Copy after login

How to remove the largest value from an array in php

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template