Saturday, July 29, 2017

Php print() function

PHP Print statement is basically use to print the content in browser webpage. Here we will learn small concept about the Print with examples.

The syntax of PHP is as follow :
int print(string $arg)

Print :

1. Print is a statement. The purpose of Print statement is to display output in webpage.
2. It can be used with parentheses Print or without parentheses Print.
3. Print doesn't support multiple arguments.
4. Print always return 1.
5. Print is slower than Echo.

Printing String using php Print:
print "Printing the text using php print";  

Output :

Printing the text using php print

Pass Multiple Argument using php Print (Doesn't Support):
As, we already discuss print statement doesn't support multiple arguments. if we pass multiple arguments, then it will show error message. Sample example for multiple argument in php.

$name = "Skptricks ";
$role = "Developer ";
$salary = 260000;
print  $name , $role , $salary; // we can concat variable/string using (,) OR (.)

Output :
PHP Parse error: syntax error, unexpected ',' in /web/com/1501313906_123213/main.php on line 9

Printing Variable using php Print:
$var="Printing the variable using php print";  
print "Variable is: $var";    

Output :
Variable is: Printing the variable using php print

Printing Escaping characters using php Print:
echo "Hello escape \"sequence\" characters";  

Output : 
Hello escape "sequence" characters

No comments:

Post a Comment