X

Rate Us :



Share with Friends :

Menu

Output Functions in PHP :

print :

This function displays output on browser & returns a boolean value 'true', if output is printed successfully, otherwise 'false'. We cannot print multiple statement with single print statement.


Note :

In PHP, the value of true is '1' and false means 'no value'.

Example :

<?php $a = "ABC"; print $a; ?>

Output :

ABC

echo :

It is same as print function. But we can print multiple statements with single echo function. This function doesn't return any value, that's why it is faster than print function.

Example :

<?php echo "ABC","DEF"; ?>

Output :

ABCDEF

var_dump :

This function displays variable value along with it's data type.

Example :

<?php $n = 111; var_dump($n); ?>

Output :

int(111)

printf() :

By using this function, we can display output with the help of formal specifier.

Example :

<?php $a = 10; $user = "Man"; printf("%s has %d cars",$user,$a); ?>

Output :

Man has 10 cars

print_r() :

By using this function, we can display all elements of an Array & property of an Object.

Example :

<?php $arr = array(10,20,30,40); print_r($arr); ?>

Output :

Array ( [0] => 10 [1] => 20 [2] => 30 [3] => 40 )