0

I have a code like this:

for($j=1;$j<3;$j++)
{
    $output.='
        <span id="<?php echo "delete-".$j; ?>">
          <?php echo $j; ?>
            </span>
             ';
}
          

Inside for loop I am using the HTML code. And I am trying to access the $j value inside for loop using php 'echo()'. But I am not getting the $j value inside php tags. How to get $j values inside php tags?

I need the output value like

<span id="delete-1">1</span>
<span id="delete-2">2</span>
<span id="delete-3">3</span>

        
            
  • 1
    If you can sort out how you use quotes, you don't need the `echo` as you can put the value directly into the output (along the lines of https://stackoverflow.com/questions/27225213/how-to-echo-inside-echo/27225234) – Nigel Ren Oct 26 '21 at 06:48
  • 1
    Did you solve your issue? If not just know that your code can be written as below, `''.$j.''` just as @NigelRen mentioned above – Anil Parshi Oct 26 '21 at 06:51
  • You cannot acccess variables in single quotes ''. Just use echo with "" double quotes and you can use variables as much as you like. – Undry Oct 26 '21 at 07:26
  • Thanks for your solution. Issue got cleared. – Sathish Selvam Oct 26 '21 at 07:31

0 Answers0