Problem
How to obtain the maximum value of a group of data
Solution
A set of data is not called by ID.
I want to obtain the data with the largest ID. What should I do.
Generally, all ID values are put in an array and then the size is compared.
But is there any other way, because this data operation takes the maximum value of ID only for assistance, if it is made into an array and then compare it feels more resource-consuming.
[]
Reference answer
Just compare the key!
Reference answer
Original Post published by liexusong at [url = http://bbs.111cn.cn/redirect.php? Goto = findpost & pid = 814074 & ptid = 100300] link mark [img] http://bbs.111cn.cn/images/common/back.gif?/img=#/url]
Just compare the key!
Isn't 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
Original Post published by liexusong at [url = http://bbs.111cn.cn/redirect.php? Goto = findpost & pid = 814077 & ptid = 100300] link mark [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 at last. I directly IF
In this way, the data is combined into an array. [Img] http://www.111cn.cn/bbs/images/smilies/default/lol.gif#/img]
Reference answer
Thank you for your ideas.
Reference answer
Max ??
Reference answer
$ SQL = 'select * FROM 'table' ORDER BY 'id' DESC LIMIT 1 ';
Copy code