2 of 410 menu

The print Function

The print function outputs the passed string or variable's value. Unlike echo, print is a language construct that always returns 1 and can be used in the context of expressions. The function accepts one mandatory parameter - the string to output.

Syntax

print(string);

Example

Outputting a simple string:

<?php print('Hello World'); ?>

Code execution result:

Hello World

Example

Using print in an expression:

<?php $res = print('Hello') * 10; echo $res; ?>

Code execution result:

Hello10

Example

Outputting a variable's value:

<?php $message = 'Welcome to PHP'; print($message); ?>

Code execution result:

Welcome to PHP

See Also

  • the echo function,
    which also outputs strings
  • the printf function,
    which formats and outputs a string
byenru