0

Please check the code below:

<?php
   $d=2;
   echo "the sum of the number is"."<sub>($d+1)</sub>";
?>

Its giving as output:

the sum of the number is <sub>(2+1)</sub>

Ideally I need the output to be "the sum of the number is <sub>3</sub>". It works fine when we don't use the HTML tags <sub>...

How can I fix this?

2 Answers 2

5

try writing it as

<?php $d=2; echo "the sum of the number is"."<sub>".($d+1)."</sub>"; ?>

the quotes give it a string representation and thus not allowing you to perform addition.

0
3

Move the expression outside the quotes:

<?php
   $d = 2;
   echo "the sum of the number is <sub>" . ($d+1) . "</sub>";
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.