PHP Tutorial

PHP Examples

PHP Practice

PHP program to demonstrate the use of printf() function

Here, we are going to demonstrate the use of printf() function in PHP?
Submitted by Nidhi, on November 18, 2020 [Last updated : March 13, 2023]

Use of printf() Function

Here, we will use the printf() function just like C programming language for formatted output.

PHP code to demonstrate the example of use of printf() function

The source code to demonstrate the use of the printf() function is given below. The given program is compiled and executed successfully.

<?php
    //PHP program to demonstrate the 
    //use of printf() function.
    
    $A = 10;
    $B = 20;
    
    $C = $A + $B;
    printf("Sum is: %d",$C);
?>

Output

Sum is: 30

Explanation

In the above program, we created two local variables $A, $B that are initialized with 10 and 20 respectively. Then we assigned the sum of $A and $B to the variable $C, and then printed the sum of $A and $B using printf() function on the webpage.

PHP Class & Object Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.