I run this and it will produce 4to1
But need an explanation on how is it outputting 4to1
Anybody can pls explain?
Echo sends output to the output buffer, If it's embedded in HTML (which is also being sent to the output buffer) then it appears that it writes that to the "source".
It output one or more strings. We can use 'echo' to output strings, numbers, variables, values, and results of expressions. Below is some usage of echo statements in PHP: Displaying Strings: We can simply use the keyword echo followed by the string to be displayed within quotes.
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.
void echo ( string $arg1 [, string $... ] ) PHP echo statement can be used to print the string, multi-line strings, escaping characters, variable, array, etc. Some important points that you must know about the echo statement are: echo is a statement, which is used to display the output.
print('2')+2
this part of code will print the number 4
to start of the line. Print
will be resolved before echo
.
Then function echo
will be resolved and echo contain to
as first and if you use print()
inside echo, it will print the function parameter as first and then number 1
.
As Andreas Scheibleger mentioned in comment, the 1
comes from the return value of print
which is always 1
, because it is not possible to echo a print()
function.
For example:
echo print(""); // 1
echo print("test"); // test1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With