PHP print_r Function

What is print_r Function and how it is used in string?


print_r function displays the information about a variable in a way that's readable by humans in PHP.



In the above printr syntax "expression" is to be printed, "return" used to print the return value.

Example :

$s = array ( array ("name" => "Sam", "Last" => "Anderson"),
array ("City" => "Dallas", "State" => "Texas"));
print_r ($s);
Result :

Array ( [0] => Array ( [name] => Sam [Last] => Anderson )
[1] => Array ( [City] => Dallas [State] => Texas )

In the above example for string, we can see that mulitiple arrays are printed in detail, so the printr function goes through each and every detail of the array.


The "printr" is actually not a function so no need to use the parenthesis.

PHP Topics

Ask Questions

Ask Question