Monday, 9 May 2011

Learn PHP online:PHP Day-6

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);
?>

No comments:

Post a Comment

Visual comparison of the two methods, creating a simple table.

Option 1, using PHP: // PHP $html = '<table>' ;     foreach ( $data as $row ) {     $html .= '<tr>...