php - How to get the minimum value from array row -


i trying minimum values column contains "xx" in column name.

below code:

<?php $array = array(  array(   'id' => 1,   '10xx' => 14,   '11xx' => 32,   '12xx' => 4  ),    array(    'id' => 2,   '10xx' => 13,   '11xx' => 36,   '12xx' => 41  ) );    foreach($array $item) {  $lowestkey = '';  foreach($item $key => $value)  {     if(strpos($key, 'xx') === 0)   {     if($lowestkey == '')    {     $lowestkey = $key;    }    else    {     if($value < $item[$lowestkey])     {      $lowestkey = $key;     }    }   }  }   echo 'lowest id ' . $item['id'] . ': ' . $item[$lowestkey] . "\n"; } ?> 

you have function it:

http://php.net/manual/en/function.min.php

echo min(2, 3, 1, 6, 7);  // 1 echo min(array(2, 4, 5)); // 2  echo min(0, 'hello');     // 0 echo min('hello', 0);     // hello echo min('hello', -1);    // -1 

combine array_values if fits better needs.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -