各位大神,小弟有个PHP的问题,如何把已经存在PHP里的数据按顺序打出来?用foreach的方法
这是已经存在PHP里的数据:<?php$difficulty_names=array(1=>"Easy",2=>"Hard",3=>"Insane");$testcham...
这是已经存在PHP里的数据:
<?php
$difficulty_names = array(
1 => "Easy",
2 => "Hard",
3 => "Insane"
);
$testchambers = array (
10 => array(
"name" => "The tenth",
"objects" => array(),
"difficulty" => 1
),
11 => array(
"name" => "A harder test chamber",
"objects" => array(
"toxic water",
"high energy pellet"
),
"difficulty" => 2
),
12 => array(
"name" => "Has three things!!",
"objects" => array(
"cube dispenser",
"falling cube",
"portal gun"
),
"difficulty" => 3
)
);
图片是结果 展开
<?php
$difficulty_names = array(
1 => "Easy",
2 => "Hard",
3 => "Insane"
);
$testchambers = array (
10 => array(
"name" => "The tenth",
"objects" => array(),
"difficulty" => 1
),
11 => array(
"name" => "A harder test chamber",
"objects" => array(
"toxic water",
"high energy pellet"
),
"difficulty" => 2
),
12 => array(
"name" => "Has three things!!",
"objects" => array(
"cube dispenser",
"falling cube",
"portal gun"
),
"difficulty" => 3
)
);
图片是结果 展开
1个回答
展开全部
echo '<table>';
foreach($testchambers as $k=>$eacharr){
echo '<tr>';
$val = ($k==10) ? 'The tenth':$k;
echo '<td>'.$val.'</td>';
echo '<td>'.$eacharr['name'].'</td>';
$objs = implode(' ', $eacharr['objects']);
$objs = ($objs=="") ? "none":$objs;
echo '<td>'.$objs.'</td>';
echo '<td>'.$difficulty_names[$eacharr['difficulty']].'</td>';
echo '</tr>';
}
echo '</table>';
foreach($testchambers as $k=>$eacharr){
echo '<tr>';
$val = ($k==10) ? 'The tenth':$k;
echo '<td>'.$val.'</td>';
echo '<td>'.$eacharr['name'].'</td>';
$objs = implode(' ', $eacharr['objects']);
$objs = ($objs=="") ? "none":$objs;
echo '<td>'.$objs.'</td>';
echo '<td>'.$difficulty_names[$eacharr['difficulty']].'</td>';
echo '</tr>';
}
echo '</table>';
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询