Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remove the largest and smallest elements from the php array

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the php array how to remove the maximum and minimum elements of the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this php array how to remove the maximum and minimum elements of the article will have a harvest, let's take a look.

Remove the method: 1, use "sort ($arr)" to sort the array in ascending order, after sorting, the first element of the array is the minimum, and the last element is the maximum; 2, delete the last element with "array_pop ($arr)" and delete the first element with "array_shift ($arr)".

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The method of removing the largest and smallest elements from php Array

Step 1. Use sort () to sort the array in ascending order

As you can see, the first element of the array after sorting is the minimum value, and the last element is the maximum value. You only need to delete these two values.

Step 2. Delete the maximum and minimum values (the first and last elements of the array)

So how to delete the first and last element of the array, you can use the array_pop () and array_shift () functions

Array_pop (): deletes the last element in the array (off the stack).

Array_shift (): deletes the first element in the array.

Array_pop ($arr); / / remove the maximum var_dump ($arr)

Array_shift ($arr); / / remove the minimum var_dump ($arr)

Note: the array_pop () and array_shift () functions modify the original array.

This is the end of the article on "how to remove the largest and smallest elements from the php array". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to remove the maximum and minimum elements of php array". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report