0

I am trying to combine the set variable $jstep_optionx with $count where x is the number within the count as $jstep_option.$count, however the only output is $count as the number.

Example as per below:

<?
$jstep_choice = 'Choice';
$jstep_options = '2';
$jstep_option1 = 'Option1';
$jstep_option2 = 'Option2';
?>

<? if ( $jstep_type == 'Choice' ) { $count = 1; $options = $jstep_options; ?>
<table class='choice'>
 <tr>
  <? while ( $count <= $options ) : $choice = $jstep_option.$count; print "<td align=center><a href=?choice=".$count.">".$choice."</a></td>"; $count++; endwhile; ?>
 </tr>
</table>
<? } ?>

Output is: a TD with 1 and a TD with 2

The output should be: a TD with Option11 and a TD with Option22

Cheers.

itzmukeshy7
  • 2,669
  • 1
  • 21
  • 29
Benjamin
  • 49
  • 3
  • 2
    Possible duplicate of [variable variables](http://stackoverflow.com/questions/3555057/variable-variables) – Sean Apr 12 '16 at 03:52
  • 2
    replace your `$choice = $jstep_option.$count;` by `$choice = "jstep_option$count";$choice = $$choice.$count;` – roullie Apr 12 '16 at 03:53
  • 3
    `$choice = ${'jstep_option'.$count}.$count;` see http://php.net/manual/en/language.variables.variable.php – Sean Apr 12 '16 at 03:55
  • Roullie's solution worked as: $choice = "jstep_option$count";$choice = $$choice; - The count at the end was not required, I did make a typo there, but hey the concept was understood, much thanks Roullie and Sean for the assist. – Benjamin Apr 12 '16 at 06:49

0 Answers0