我試圖從任何列中獲取列值中包含「xx」的最小值。如何從陣列行中獲取最小值
下面是我的代碼:
<?php
$array = array(
array(
'id' => 1,
'10xx' => 14,
'11xx' => 32,
'12xx' => 4
),
array(
'id' => 2,
'10xx' => 13,
'11xx' => 36,
'12xx' => 41
)
);
foreach($array as $item)
{
$lowestKey = '';
foreach($item as $key => $value)
{
if(strpos($key, 'xx') === 0)
{
if($lowestKey == '')
{
$lowestKey = $key;
}
else
{
if($value < $item[$lowestKey])
{
$lowestKey = $key;
}
}
}
}
echo 'lowest for id ' . $item['id'] . ': ' . $item[$lowestKey] . "\n";
}
?>
「但我不能」 - _why_?什麼是輸出?另外,看看http://php.net/manual/en/array.sorting.php – akluth
http://php.net/manual/en/function.min.php –