PHP "echo" can display multiple arrgument string output. "echo" is a language that is not a function, there is no need to use parentheses but if you use more than one parameter then you need parentheses. it works faster than "print" Or "Echo" can be used with parenthese and without parentheses.
PHP "print" can only single arrgument string output. "print" statement also works like "echo" statement but it contains display one string output.
PHP "echo" can display many of the data that we get as output on the display such as string, numbers, characters, variables etc. and it will no return value and "echo" works faster than "print".
<!DOCTYPE html> <html> <body> <?php //Defined Variables. $student = 'To learning PHP'; $source = 'w3alert.com'; // Variables Inside "echo" Statement. echo "$student at $source <br />"; // Simple Variable Display. echo $student; echo "<br />"; echo $source; echo "<br />"; // Muliple Arrgument String. echo $student , $source; echo "<br/"; // With parenthese "echo" Statement. echo ($student); ?> </body> </html>
In the above example: $student and $source, there are two varibles with some values each. lets we want to print all variable together using echo. All variable names are set inside an echo statement, this will show the output.
The "print" remains the same as the "echo" statement, but the "print" statement only works with one argument output at a time. it will return 1 value and it is slower than "echo".
<!DOCTYPE html> <html> <body> <?php //Defined Variables. $welcome = "Hello w3alert!"; $number = "098765545"; // Displaying variables print $welcome; print "<br>"; //With parenthese "print" Statement. print ($number); ?> </body> </html>
In the above example: Declared two variables $welcome and $number. lets we want to print the variable using print or print(). we simply defined variable inside print statement with or without parentheses.