请有人帮忙输出多维数组。
不确定我哪里出错了。 排序顺序看起来正确,但它没有显示结果。
<?php
$atest = Array ( "0" => Array ( "id" => "913", "testname" => "qwerty1", "i" => "1" ),
"1" => Array ( "id" => "913", "testname" => "test22", "i" => "2" ),
"2" => Array ( "id" => "913", "testname" => "American1", "i" => "3" ),
"3" => Array ( "id" => "913", "testname" => "Eagle4", "i" => "4" ) );
$range = range('A','Z');
$output = array();
$output['#'] = array();
foreach($range as $letter){
$output[$letter] = array();
}
foreach($atest as $test){
if ($test["testname"] !='') {
$uc = ucfirst($test["testname"]);
if(array_search($uc[0], $range) === FALSE){
$output['#'][] = $uc;
} else {
$output[$uc[0]][] = $uc;
}
}
}
foreach($output AS $letter => $result){
echo $letter . "<br/>--------<br/>\n";
sort($result);
foreach($result AS $indresult){
echo '<a href="index.php?option=com_comprofiler&task=page&user=' . (int) $indresult['id'] . '&b=' . $indresult['i'] . '">' . $indresult['testname'] . '</a><br/>';
}
echo "<br/>\n";
}
?>
答案 0 :(得分:0)
尝试使用print_r
函数,例如对于数组转储:
print_r($atest);
答案 1 :(得分:0)
答案 2 :(得分:0)
您不是将整个子阵列放入$output
,而是只放$uc
。将中间foreach
循环更改为:
foreach($atest as $test){
if ($test["testname"] !='') {
$uc = ucfirst($test["testname"]);
if(array_search($uc[0], $range) === FALSE){
$output['#'][] = $test;
} else {
$output[$uc[0]][] = $test;
}
}
}