Saturday, 15 August 2015

php - find maximum value of a parameter within an array -


I have an array in the following format, which I received through the following code:

  echo print_r ($ list); The array is:  
  array ([0] => array ([ID] => 105 [id_parent] => 1 [title] => pellets [ID_product ] = & Gt; 12 9 [product_name] = & gt; Acage Premium App A1 pellets [constructor] => same [id_space] => 105 [id_category] => 5 [unit size] => gt; ; [Weight] => 15] [1] => Array ([ID] => [[ID_para] = 102] [[Title] => Firwood [ID_product] => 114 [product_name] = Gtc: ID] => [[ID_per] => 1 [Title] => Instant [ID_product] => 118 [product_name] => Nilgiri bulk b D [gtc: / Pre> 

What do I have to do, to get the maximum value parameter weightvol `in this array.

I have tried: echo max ($ List, 'weightwall');

and

  echo max ($ list ['weightvol']);  
< P> But something is telling me that max () is not the right function to use in this case. Can anyone help me here?

  echo max (array_column ($ list, 'weightvol'));  

If you are running PHP> = 5.5.0;

  echo max (array_map (function ($ value) {return $ value ['weightvol'];}, $ list));  

For earlier versions of PHP


No comments:

Post a Comment