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 find the third minimum value of an array by php

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, I would like to share with you how to find the third minimum value of the array php related knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

Methods: 1, use array_values () to convert the array into an indexed array, syntax "array_values (original array)"; 2, use sort () to sort the array in ascending order, syntax "sort (indexed array)", when the element with an index of 2 is the third minimum value; 3, use the "indexed array name [2]" statement to get.

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

The method of finding the third minimum of Array by php

In PHP, the array is sorted in ascending order so that the small value comes first and the large value comes last. The first three values (a [0], a [1], a [2]) are the first, second, and third small values. Take out the element with index 2 (a [2]).

Here are the specific steps.

1. Convert an array to an indexed array

Using array_values () to get the values of all the elements in the array, you can convert the associative array into an indexed array, ensuring that the array is indexed. (in this way, the third minimum value can be extracted later using the index value.)

2. Sort the indexed array in ascending order

Use the sort () function to sort the array in ascending order, so that the array elements are sorted from small to large.

Sort ($value); var_dump ($value)

At this point, the first third element, with an index of 2, is the third minimum value required.

3. Get the third minimum value

You only need to use the form of "array name [2]" to get the third element after sorting.

The third lowest value of the echo array is:. $value [2]

These are all the contents of the article "how to find the third lowest value in an array by php". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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