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.

4
  • 2
    Possible duplicate of variable variables Commented Apr 12, 2016 at 3:52
  • 2
    replace your $choice = $jstep_option.$count; by $choice = "jstep_option$count";$choice = $$choice.$count; Commented Apr 12, 2016 at 3:53
  • 3
    $choice = ${'jstep_option'.$count}.$count; see php.net/manual/en/language.variables.variable.php Commented Apr 12, 2016 at 3: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. Commented Apr 12, 2016 at 6:49

0

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.