Output function in php

Print :

This function displays output on browse and returns value true if output is printed successfully, otherwise it returns false.

Example

 

<?php

                        $a= print”codelack”;

                        Print”<br>”;

                        Print $a;  // returns either true or false.

          ?>

 

Output:   codelack<br/>1

Echo:

  •  It is  same as print but it does not return any value so  that its performance is faster than print function.
  • We can also print multiple statements with an echo function.

Example

 

<?php

 Echo "codelack", "com","tutorial" ;

?>

 

Output: codelackcomtutorial.

 

var-dump:

using this function we can display the value of variable along with data types.

 

  <?php
      $k=100;

     $y="codelack";

      Var_dump($k);

      Var_dump($y);
  ?>

 

Output: int (100) string 8  codelack

Printf:-

Using this function we can print variables with the help of format specifiers.

 

<?php

$k=100;

$h="codelack”;

Printf(“%d”,$k);

Printf(“%s”,$h);

?>

 

Output :  100 codelack

Print_r: 

Using this function, we can display  all elements of array and properties of object.

 

<?php

$arr=array(10,20,40,50);

Print_r($arr);

?>

 

Output:  array

[0]=10

[1]=20

[3]=40

[4]=50

 

NOTE : On viewing the source code , the array is shown systematically on the screen.

Scroll Up