PHP print Function Tutorial

The print is the one of the most popular function used in PHP scripts and programs. The print simply used to print specified data, value, variable etc. into the standard output. In this tutorial we will examine different usecases and examples about the PHP print.

print Syntax

The PHP print function has very simple syntax. It accepts single parameter which printed to the standard output.

print DATA
  • DATA is a data which can be a string, integer, variable etc.

The print function returns an integer as the value which describes whether provided data is printed properly.

Print String

One of the most popular use cases for the print function is the printing string to the standard output. The standard output is generally a console or a web page. The string value can be provided with double quotes or using a single quoto.

print "I am wisetut.com";

print "I"." am "."wisetut.com";

print 'I am wisetut.com';

Print Variable

The print function can be also used to print variables or variables values easily. The variable name is provided as parameter to the print function.

$a="I am wisetut.com";

$b="I"." am "."wisetut.com";

$c='I am wisetut.com';


print $a;

print $b.$c;

Print Array

The array structure stores multiple items in a single variable. The array can not be printed by using the print function. The print_r fnuction can be used to print an array.

$names=array("ismail","ahmet","ali");

print_r $names;

print vs echo

The echo statement is another popoular way to print something in PHP. The print and echo are very same with a little differencies. The echo may accepts multiple items to print but the print accepts only single item.

Leave a Comment