How can i get the second highest element value in a multidimensional array. I use this function to get the highest value. But how can i find the second highest.
function get_max($array)
{
$max = -999999999;
$found_item = null;
foreach ($array as $key => $value) {
if ($value['transaction_no'] > $max) {
$max = $value['transaction_no'];
$found_item = $value;
}
}
return $found_item;
}
For example if i call get_max($transactions) i get the array number 4 because it has the highest value: 5 in the transaction_no. But how can i get the second highest? for example when i call for get_second_max($transactions) i should get array number 3 because it has 4 in the transaction_no.
$transactions = Array
(
[0] => Array
(
[transaction_user_id] => 359691e27b23f8ef3f8e1c50315cd506
[transaction_no] => 1
[transaction_total_amount] => 589.00
[transaction_date] => 1335932419
[transaction_status] => cancelled
)
[1] => Array
(
[transaction_user_id] => 9def02e6337b888d6dbe5617a172c18d
[transaction_no] => 2
[transaction_total_amount] => 79.00
[transaction_date] => 1336476696
[transaction_status] => cancelled
)
[2] => Array
(
[transaction_user_id] => 9def02e6337b888d6dbe5617a172c18d
[transaction_no] => 3
[transaction_total_amount] => 299.00
[transaction_date] => 1336476739
[transaction_status] => cancelled
)
[3] => Array
(
[transaction_user_id] => 9def02e6337b888d6dbe5617a172c18d
[transaction_no] => 4
[transaction_total_amount] => 79.00
[transaction_date] => 1336476927
[transaction_status] => cancelled
)
[4] => Array
(
[transaction_user_id] => 8e9050a3646c98342b9ba079fba80982
[transaction_no] => 5
[transaction_total_amount] => 129.00
[transaction_date] => 1336477032
[transaction_status] => cancelled
)
)
order byandlimit