You are here: Home / Topics / PHP Program To Print Sum Of Digits

PHP Program To Print Sum Of Digits

Filed under: PHP on 2022-11-16 13:33:14

The below program gives the sum of two variables x and y. The PHP echo statement is used to output the text and sum value to the screen. In a similar way, codes can be written to get a sum of multiple variables in PHP.

Example

<!DOCTYPE html>

<html>

<body>

  <?php

$txt1 = "Sum of x and y is:";

$x = 1234;

$y = 4321;  

echo "<h3>" . $txt1 . "</h3>"; echo $x + $y;

?>

  </body>

</html>

Output

Sum of x and y is: 5555
About Author:
V
Vishal Gupta     View Profile
Hi, I am Vishal Gupta. I like this Website for learning MCQs. This website is good for preparation.