0

I have a 'loop' to go through but I can't work out how to do this. I want to do something like

array1=(2,3,10,11,13) array2=(20,22,24,27,29)

and then loop though for each.

Here is the long hand version that I want to produce.

Thanks in advance...

<?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/>';} ?>
2
  • Sorry can you explain it better? I can't figure out what it is that you are trying to do... Commented Dec 23, 2013 at 12:38
  • Not sure I understand what you mean... You want to loop through both arrays at the same time? I mean loop array1[1] array2[1] loop array1[2] array2[2] etcetera? Or is is it array1[1] array1[2]... then array2[1] array[2]... ? Commented Dec 23, 2013 at 12:39

1 Answer 1

1

my bad, I was doing it wrong!!

 <?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/>';}
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.