12

Ok so i have this php foreach loop

<?php foreach ($step_count->rows as $step) { ?>

and $step will be the step numbers 1, 2, 3, 4, 5 up to the total steps

within the loop i a need to set the value of the images within the loop to standard_image_1 or whatever step there is...so for example

<input value="<?php echo {$standard_image_"$step['number']"}; ?>" />

so basically i need the variable $standard_image_1 and so on depending on the steps but i dont know the correct syntax to do this

Chris Baker
  • 49,926
  • 12
  • 96
  • 115
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321

1 Answers1

45

Look at the docs for "variable variables" - http://php.net/manual/en/language.variables.variable.php

<?php echo ${'standard_image_'.$step['number']}; ?>

Here's a mock-up, using the details you've given: http://codepad.org/hQe56tEU

Chris Baker
  • 49,926
  • 12
  • 96
  • 115
  • 1
    This is correct, and technically it answers the question. But I agree with Quention, it's probably best to use an associative array. – Zecc Jun 15 '11 at 15:13