Home > Backend Development > PHP Tutorial > How to get the largest value in a set of data_PHP Tutorial

How to get the largest value in a set of data_PHP Tutorial

WBOY
Release: 2016-07-13 10:50:56
Original
957 people have browsed it



Question
How to get the data with the largest median value in a set
Solution
There is a set of data that is not called in order of ID.
I want to get the data with the largest ID. What do I do.

Generally, all ID values ​​are put into an array and then compared in size.
But is there any other way? Because I am only trying to retrieve the maximum ID value for data manipulation this time. If I make it into an array and compare it, it will consume more resources.

[ ]


Reference answer
Just compare keys!
Reference answer
Original post by liexusong on 2009-1-4 00:09 [url=http://bbs.111cn.cn/redirect.php?goto=findpost&pid=814074&ptid=100300]Link tag [img]http://bbs. 111cn.cn/images/common/back.gif[/img][/url]
Just compare keys!
Wouldn't it be better to put it in the array?
Reference answer
$the_max = NULL;

foreach($array as $key => $value) {

if($key > $the_max) $the_max = $key;

}

echo $array[$the_max]; //This is the answer


Copy code
Reference answer
The original post was posted by liexusong on 2009-1-4 00:11 [url=http://bbs.111cn.cn/redirect.php?goto=findpost&pid=814077&ptid=100300]Link tag [img]http://bbs. 111cn.cn/images/common/back.gif[/img][/url]

$the_max = NULL;
foreach($array as $key => $value) {
if($key > $the_max) $the_max = $key;
}
echo $array[$the_max]; //This is the answer
Thank you.
Reference answer
I didn’t have FOREACH in the end, I just IF
This leaves only combining the data into arrays. [img]http://www.111cn.cn/bbs/images/smilies/default/lol.gif[/img]
Reference answer
Thank you for the ideas you provided.
Reference answer
Isn’t it possible to max??
Reference answer
$sql = 'SELECT * FROM `table` ORDER BY `id` DESC LIMIT 1';


Copy code

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632591.htmlTechArticleProblem How to get a set of data with the largest median value Solution There is a set of data that is not called in ID order. I I want to get the piece of data with the largest ID. What do I do. Generally, all...
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