-1

I wrote a simple script for echoing total of two variables to <h1> tag, but it gives strange results

<?php

    $i=10; $j=20;

    var_dump($i);
    var_dump($j);
    echo '<h1>'.$i+$j.'</h1>';

?>

Result of this script:

int(10)
int(20)
20</h1>

I was expecting 30 but it ate up <h1> tag, how can i do this as expected?

viral
  • 3,724
  • 1
  • 18
  • 32

1 Answers1

2

Try this:

echo '<h1>'.($i+$j).'</h1>';

This explains why you need to concatenate like this. Here is a working demo.

Community
  • 1
  • 1