w3programmers - PHP Basic Part-2: PHP echo VS print statement

PHP Basic Part-2: PHP echo VS print statement

PHP echo VS print statement

echo vs print

If you want to show any results from the server in PHP, you need to use either echo or print. These two are languages ​​Construct in PHP . Language Construct are faster than the function. Because language Construct can show results without compiling, on the other hand, the functions can show results after compiling. And because of those languages ​​Constructs can write parenthesis “i.e ()”   with or without parenthesis.

echo "Hello world";
echo ("Hello World");
print "Hello World";
print ("Hello World");

Following all ways are correct:

Language Constructs are called basic components of any language.

We will show you deference between Echo And Print with example :

1. You can take multi parameters in echo if you are not used parenthesis. On the other hand, you can use only single parameter in print , whether it is with parenthesis or without parenthesis. Notice the following examples:

echo "1"; //valid
echo "1","2"; //valid
echo ("1","2"); //Invalid
print "1";  //valid
print ("2"); //Valid
print "1","2";  //Invalid
print ("1","2"); //Invalid

The above line 2, 3, 5, 6 is correct.   The rest will show wrong.

2. echo has no return value.   On the other hand print boolean true means, it will return 1. Seeing the example below will clear the rest:

echo print (5); // Output 51

Here we get 5 as the result of print. Then return result of print 1 we get through echo. For which we get 51 together here as a result.

One comment to “PHP Basic Part-2: PHP echo VS print statement”

Leave a Reply

Your email address will not be published. Required fields are marked *