PHP find second highest element value in a multidimensional array -


How can I get the second highest element value in a multi-dimensional array? I use this function to get the highest value. But how can I achieve the second highest?

  function get_max ($ array) {$ max = -999999999; $ Found_item = null; Forex currency ($ array = $ formatted as $ key) {if ($ value ['transaction_no'] & gt; $ max) {$ max = $ value [transaction_no ']; $ Found_item = $ value; }} $ Found_item; } For example, if I call  get_max ($ transactions)  then I get array number 4 because the highest value is: 5  transaction_no . But how can I get the second highest? For example when i call get_second_max ($ transaction)  for  I should get array number 3 because it is 4 in transaction_no $ [Transaction] = array ([0] = & gt; array ([transaction_user_id] => 359691e27b23f8ef3f8e1c50315cd506 [transaction_no] => 1 [transaction_total_amount] => 589.00 [TRANSACTION_DATE ] = & Gt; +1335 9 3241 9 [transaction_status] = & gt; canceled) [1] => Array ([Transaction_user_id]> 9def02e6337b888d6dbe5617a172c18d [transaction_no] => 2 [transaction_total_amount] => 79.00 [transaction_date ] => 1336476696 [transaction_status] = & gt; canceled) [2] => Erre ([transaction_user_id] => 9def02e6337b888d6dbe5617a172c18d [Transaction_no] => 3 [transaction_total_amount] => 299.00 [transaction_date ] => 1336476739 [transaction_status] = & gt; canceled) [3] => Array ([transaction_user_id] => 9def02e6337b888d6dbe5617a172c18d [transaction_no] => 4 [transaction_total_amount] => 79.00 [TRANSACTION_DATE ] = & Gt; +1336476 9 7 [transaction_status] = & gt; canceled) [4] = & gt; Array ([transaction_user_id] = & gt; 8e9050a3646c98342b9ba079fba80982 [transaction_no] = & gt; 5 [transaction_total_amount] = & gt; 129.00 [TRANSACTION_DATE] = & gt; + 1336477032 [transaction_status] = & gt; Canceled))  

  & lt; Php function get_max ($ array) {$ all = array (); Forex Currency ($ array = $ value as $ key) {$ all [] = $ value [transaction_no ']; } Rupees ($ all); $ All [1] return; }  

To return the array and not just the value:

  function get_max ($ array) {$ all = array (); Forex Currency ($ Key = & gt; $ value as the $ key) {/ * Create the array where the key transaction is no, and the value is this transaction_no * / $ all [$ value [transaction_no ']] = $ value; } / * Now sort the array by key (transaction_no) * / krsort ($ all); / * Get second array and return it (see link below) * / return array_slice ($ all, 1, 1) [0]; }  


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -