我有一个'循环'可以通过,但我无法弄清楚如何做到这一点。我想做像
这样的事情ARRAY1 =(2,3,10,11,13) 数组2 =(20,22,24,27,29)
然后为每个循环。
这是我想要制作的长手版本。
提前致谢...
<?php if($values['2']['value'] == 'No'){echo $values['2']['description'].'<br/>';} ?>
<?php if($values['20']['label'] == 'Other' && $values['20']['value'] != ''){echo 'Q1. '.$values['20']['value']; echo '<br/>';} ?>
<?php if($values['3']['value'] == 'No'){echo $values['3']['description'].'<br/>';} ?>
<?php if($values['23']['label'] == 'Other' && $values['23']['value'] != ''){echo 'Q2. '.$values['23']['value']; echo '<br/>';} ?>
<?php if($values['10']['value'] == 'No'){echo $values['10']['description'].'<br/>';} ?>
<?php if($values['22']['label'] == 'Other' && $values['22']['value'] != ''){echo $values['10']['description'].'<br/>';} ?>
<?php if($values['11']['value'] == 'No'){echo $values['11']['description'].'<br/>';} ?>
<?php if($values['24']['label'] == 'Other' && $values['24']['value'] != ''){echo 'Q4. '.$values['24']['value']; echo '<br/>';} ?>
<?php if($values['12']['value'] == 'No'){echo $values['12']['description'].'<br/>';} ?>
<?php if($values['25']['label'] == 'Other' && $values['25']['value'] != ''){echo 'Q5. '.$values['25']['value']; echo '<br/>';} ?>
<?php if($values['13']['value'] == 'No'){echo $values['13']['description'].'<br/>';} ?>
<?php if($values['27']['label'] == 'Other' && $values['27']['value'] != ''){echo 'Q6. '.$values['27']['value']; echo '<br/>';} ?>
<?php if($values['21']['value'] == 'No'){echo $values['21']['description'].'<br/>';} ?>
<?php if($values['26']['label'] == 'Other' && $values['26']['value'] != ''){echo 'Q7. '.$values['26']['value']; echo '<br/>';} ?>
<?php if($values['29']['value'] == 'No'){echo $values['29']['description'].'<br/>';} ?>
<?php if($values['49']['label'] == 'Other' && $values['49']['value'] != ''){echo 'Q8. '.$values['49']['value']; echo '<br/>';} ?>
<?php if($values['39']['value'] == 'No'){echo $values['39']['description'].'<br/>';} ?>
<?php if($values['48']['label'] == 'Other' && $values['48']['value'] != ''){echo 'Q9. '.$values['48']['value']; echo '<br/>';} ?>
答案 0 :(得分:1)
我的坏,我做错了!!
<?php
$risk_numbers = array(
'2' => '20',
'3' => '23',
'10' => '22',
'11' => '24',
'12' => '25',
'13' => '27',
'21' => '26',
);
foreach($risk_numbers as $description => $other) {
if($values[$description]['value'] == 'No'){echo $values[$description]['description'].'<br/>';}
if($values[$other]['label'] == 'Other' && $values[$other]['value'] != ''){echo $values[$other]['value']; echo '<br/>';}
}
?>