PHP print() Function
The print() function in PHP is used to output one or more string.
Syntax
1 2 3 |
print ( string $arg ) |
Parameter
arg(required)– This parameter represents the input data. It can take one or more arguments.
Return
This function returns an integer value 1.
Example 1
1 2 3 4 5 6 7 8 |
<?php // initializing the string $str = "Hello PHP World!"; // printing the strng with print() function print $str; ?> |
Output
1 2 3 |
Hello PHP World! |
Example 2
1 2 3 4 5 6 7 8 9 10 |
<?php // initializing string1 $str1="PHP is an "; // initializing string 2 $str2="easy programming language to learn!"; // printing both the string print $str1 . " " . $str2; ?> |
Output
1 2 3 |
PHP is an easy programming language to learn! |
Example 3
1 2 3 4 5 6 |
<?php $age=array("Reema"=>"22"); print "I am " . $age['Reema'] . " years old."; ?> |
Output
1 2 3 |
I am 22 years old. |
Example 4
1 2 3 4 5 6 7 |
<?php $str = "Hello PHP!"; print $str; print "\nThis is an print() function example."; ?> |
Output
1 2 3 4 |
Hello PHP! This is an print() function example. |