Hello World
suggest changeThe most widely used language construct to print output in PHP is echo
:
echo "Hello, World!\n";
Alternatively, you can also use print
:
print "Hello, World!\n";
Both statements perform the same function, with minor differences:
echo
has avoid
return, whereasprint
returns anint
with a value of1
echo
can take multiple arguments (without parentheses only), whereasprint
only takes one argumentecho
is slightly faster thanprint
Both echo
and print
are language constructs, not functions. That means they do not require parentheses around their arguments. For cosmetic consistency with functions, parentheses can be included. Extensive examples of the use of echo
and print
are available elsewhere.
C-style printf
and related functions are available as well, as in the following example:
printf("%s\n", "Hello, World!");
See Outputting the value of a variable for a comprehensive introduction of outputting variables in PHP.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents