php - Get the maximum value from an element in a multidimensional array? -


I am trying to select the maximum value for a particular key in a multi-dimensional array. I have a problem in the question "being" ...

So, the array (which is more than I am posting here)

  [ 0] = & gt; StdClass object ([ID] => 70 [cust] => 4 [dnum] => 1 [top] => array ([0] => 66) [1] = & Gt; StdClass object ([ID] => 43 [cust] => 42 [dnum] => 2 [upper] => array ([0] => 77)) [2] = & Gt; 0 [upper] = & gt; Array ([0] => 99))  
P> I am trying to find the maximum value of "dnum" in the entire array, so in this example, $ max = 2. I know that the maximum function allows me to do this, but I'm not sure how the reference dnum element without putting the whole thing in a foreach loop, and if I do this, then the maximum function to use Will not, will not it?

So, I can not do this at all:

  $ max = max ($ myarray [] - gt; dnum);  

Is there any way to do this without rebuilding the entire array?

  $ max = 0; Forex Currency ($ Orange $ OBJ) {If ($ obj-> dnum> $ Max) {$ max = $ obj-> Dnum; }}  

If your highest number is not negative then this function will work correctly (negative, empty array and 0s 0 as max).

Because you are using an object, which can have custom properties / structures, I do not believe there is actually any 'predefined' function that you can use to obtain it Are there. Simultaneously, you can only use a force loop.

You can not really be away from a foreshop loop, since internal functions use a foreshop loop, it is only behind the scenes.

Another solution is

  $ numbers = array (); Forex Currency ($ Orange $ $ obj) {$ numbers [] = $ obj- & gt; Dnum; } $ Max = maximum ($ number);  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -