Friday 22 April 2011

Types of Print Function in PHP



Types of Print Function in PHP

Print: By using this function we can display the outputs on the browser. This function returns the Boolean value true. We cannot print the multiple statements using this function.
Ex:
<?php
$rval=print"welcome";
?>
Echo: By using this function we can display the multiple statements on the browser. Compare with print function, echo is very faster. Because it won’t return the any value.
Ex:
<?php
$rval="welcome";
echo $rval;
?>
Printf: By using this function we can display the output with the help of the formats specifies.
Ex:
<?php
$user="danPHP";
$cars=5;
printf("%s has %d cars",$user,$cars);
?>
sprintf: This is same as printf, but instead of displaying the output on the web page, it returns that output.
Ex:
<?php
$user="danphp";
$cars=5;
$rv=sprintf("%s has %d cars",$user,$cars);
echo $rv
?>
var_dump: This function displays the variable value along with the variable data type.
Ex:
<?php
$user="Danphp";
$cars=5;
var_dump($cars);
var_dump($Danphp);
?>
print_r: This function displays the r elements of array and properties of an object.
Ex:
<?php
$arr=array(10,20,30);
print_r($arr);
?>

1 comment:

  1. hi sir i am ramesh, student in your morning batch 7:10am .. i dont know how to run viedos in our php website... please tell me any ideas... http://www.danphp.com/p/php-notes-php-tutorial-notes.html

    ReplyDelete