Part 2: PHP echo and print statement

Part 2: PHP echo and print statement
Image

In PHP, if you want to display something or any result from the server in the browser, you have to use either echo or print. In PHP these two are Language Construct. And language constructs are usually faster than functions. Because language constructs can show the required results without any compile, on the other hand the functions can show the results after compiling. And since these two languages ​​are Construct, you can write in two ways without parenthesis “i.e ()” or with parenthesis.

 

All of the following methods are correct:

Image

Language constructs are also called basic elements of any language.

Is there any difference between echo and print in Php? Want to see with examples.

 

Yes, there are some differences between echo and print. Let’s take a look at an example:

 

1.     In echo you can take one parameter, if you do not use parenthesis. On the other hand, in print you can take only one parameter, whether it is with parenthesis or without parenthesis. Notice the following examples:

Image

The lines 2,3,5,6 above are correct. The rest will look wrong.

 

echo has no return value. On the other hand print boolean true means 1 returns. The rest will be clear when you see the following example:

Image

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

 

Leave a Reply

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