PHP | print_r() Function
Last Updated :
11 Jul, 2025
Improve
The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable.
Syntax:
PHP
Output:
PHP
Output:
print_r( $variable, $isStore )Parameters: This function accepts two parameters as shown in above syntax and described below.
- $variable: This parameter specifies the variable to be printed and is a mandatory parameter.
- $isStore: This an option parameter. This parameter is of boolean type whose default value is FALSE and is used to store the output of the print_r() function in a variable rather than printing it. If this parameter is set to TRUE then the print_r() function will return the output which it is supposed to print.
<?php
// PHP program to illustrate
// the print_r() function
// string variable
$var1 = "Welcome to GeeksforGeeks";
// integer variable
$var2 = 101;
// array variable
$arr = array('0' => "Welcome", '1' => "to", '2' => "GeeksforGeeks");
// printing the variables
print_r($var1);
echo"\n";
print_r($var2);
echo"\n";
print_r($arr);
?>
Welcome to GeeksforGeeks 101 Array ( [0] => Welcome [1] => to [2] => GeeksforGeeks )Program 2:
<?php
// PHP program to illustrate the print_r()
// function when $isStore is set to true
// array variable
$arr = array('0' => "Welcome", '1' => "to",
'2' => "GeeksforGeeks");
// storing output of print_r() function
// in another variable
$results = print_r($arr, true);
echo $results;
?>
Array ( [0] => Welcome [1] => to [2] => GeeksforGeeks )Reference: https://www.php.net/manual/en/function.print-r.php