Skip to playerSkip to main content
  • 11 years ago
print

(PHP 4, PHP 5)
print — Output a string

Description

int print ( string $arg )
Outputs arg.

print is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.

Parameters

arg
The input data.

Return Values

Returns 1, always.

Examples

Example #1 print examples

"foo");

print "this is {$bar['value']} !"; // this is foo !

// Using single quotes will print the variable name, not the value
print 'foo is $foo'; // foo is $foo

// If you are not using any other characters, you can just print variables
print $foo; // foobar

print
Notes

Note: Because this is a language construct and not a function, it cannot be called using variable functions.
See Also

echo - Output one or more strings
printf() - Output a formatted string
flush() - Flush system output buffer
Heredoc syntax
add a note add a note
User Contributed Notes 14 notes

up
down
22 user at example dot net 7 years ago
Be careful when using print. Since print is a language construct and not a function, the parentheses around the argument is not required.
In fact, using parentheses can cause confusion with the syntax of a function and SHOULD be omited.

Most would expect the following behavior:


But since the parenthesis around the argument are not required, they are interpretet as part of the argument.
This means that the argument of the first print is

("foo") && print("bar")

and the argument of the second print is just

("bar")

For the expected behavior of the first example, you need to write:

Category

📚
Learning
Comments

Recommended