Echo and print Statements
PHP echo and print Statements
echo and print are more or less the same. They are both used to output data to the screen.
The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
Example
<?php echo "PHP is Fun!
"; echo "Hello world!"; echo "I'm about to learn PHP!
"; echo "This ", "string ", "was ", "made ", "with multiple parameters."; ?>
print Statement
The print statement can be used with or without parentheses: print or print().
Display Text
The following example shows how to output text with the print command (notice that the text can contain HTML markup):
Example
<?php print "PHP is Fun!
"; print "Hello world!"; print "I'm about to learn PHP!"; ?>
PHP Data Types
Variables can store data of different types, and different data types can do different things.
PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource
PHP String
A string is a sequence of characters, like "Hello world!".
A string can be any text inside quotes. You can use single or double quotes:
Example
<?php $x = "Hello world!"; $y = 'Hello world!';echo $x;
echo "
";
echo $y;
?>