有谁知道如何在PHP中获取第2和第3列的最大值和最小值?
$ar = array(array(1, 10, 9.0, 'HELLO'),
array(1, 11, 12.9, 'HELLO'),
array(3, 12, 10.9, 'HELLO'));
输出应该是:
MAX(12.9) 分(10)
答案 0 :(得分:2)
另一个选择
<?php
function array_rotate( $array )
{
$rotated = array();
foreach ( $array as $rowIndex => $col )
{
foreach ( $col as $colIndex => $value )
{
$rotated[$colIndex][$rowIndex] = $value;
}
}
return $rotated;
}
$ar = array(array(1, 10, 9.0, 'HELLO'),
array(1, 11, 12.9, 'HELLO'),
array(3, 12, 10.9, 'HELLO'));
$ar = array_rotate( $ar );
echo max( $ar[2] ), "\n", min( $ar[1] );
答案 1 :(得分:1)
<?php
$ar = array(array(1, 10, 9.0, 'HELLO'),
array(1, 11, 12.9, 'HELLO'),
array(3, 12, 10.9, 'HELLO'));
function col($tbl,$col){
$ret = array();
foreach ($tbl as $row){
$ret[count($ret)+1] = $row[$col];
}
return $ret;
}
print (max(col($ar,2))."\n");
print (min(col($ar,1))."\n");
?>
这是你要找的?我猜它不是最有效的方式。