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)
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:
<?php print "Printing the text using php print"; ?>
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.
<?php $name = "Skptricks "; $role = "Developer "; $salary = 260000; print $name , $role , $salary; // we can concat variable/string using (,) OR (.) ?>
PHP Parse error: syntax error, unexpected ',' in /web/com/1501313906_123213/main.php on line 9
Printing Variable using php Print:
<?php $var="Printing the variable using php print"; print "Variable is: $var"; ?>
Variable is: Printing the variable using php print
Printing Escaping characters using php Print:
<?php echo "Hello escape \"sequence\" characters"; ?>
Hello escape "sequence" characters