Hi there,
I got this array, $data, and I am wondering how I can manage to make php find the biggest key value - which is 1746.[text]Array
(
[2005] => Array
(
[perm] => 317
[temp1] => 0
[temp2] => 93
[temp] => 93
[unba] => 13
[rows] => 292
[jazz] => 0
[news] => 0
[cssp] => 0
[csst] => 0
[cssu] => 0
)
[2006] => Array
(
[perm] => 1292
[temp1] => 16
[temp2] => 300
[temp] => 316
[unba] => 43
[rows] => 1171
[jazz] => 0
[news] => 0
[cssp] => 0
[csst] => 0
[cssu] => 0
)
[2007] => Array
(
[perm] => 450
[temp1] => 2
[temp2] => 879
[temp] => 881
[unba] => 83
[rows] => 460
[jazz] => 0
[news] => 0
[cssp] => 0
[csst] => 0
[cssu] => 0
)
[2008] => Array
(
[perm] => 1150
[temp1] => 2
[temp2] => 1744
[temp] => 1746
[unba] => 206
[rows] => 1046
[jazz] => 0
[news] => 0
[cssp] => 0
[csst] => 0
[cssu] => 0
)
[2009] => Array
(
[perm] => 1338
[temp1] => 1
[temp2] => 1695
[temp] => 1696
[unba] => 86
[rows] => 1272
[jazz] => 346
[news] => 260
[cssp] => 69
[csst] => 55
[cssu] => 1
)
[2010] => Array
(
[perm] => 574
[temp1] => 6
[temp2] => 748
[temp] => 754
[unba] => 35
[rows] => 663
[jazz] => 192
[news] => 122
[cssp] => 88
[csst] => 112
[cssu] => 6
)
[2011] => Array
(
[perm] => 2
[temp1] => 0
[temp2] => 4
[temp] => 4
[unba] => 1
[rows] => 1
[jazz] => 0
[news] => 1
[cssp] => 0
[csst] => 0
[cssu] => 0
)
)
[/text]
Find the biggest array value
Moderator: General Moderators
Re: Find the biggest array value
use max() function to find the largest value..see php website to use the max() function
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Find the biggest array value
Probably a slicker way, but try:
Code: Select all
$max = 0;
foreach($array as $item) {
$max = (max($item) > $max) ? max($item) : $max;
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Find the biggest array value
Code: Select all
$max = ~PHP_INT_MAX;
foreach ($array as $item) {
$max = max($max, max($item));
}