PHP | print_r() Function Last Updated : 26 Apr, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The print_r() function is a built-in function in PHP and is used to print or display information stored in a variable. Syntax: 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. Return Value: If the $variable is an integer or a float or a string the function prints the value of the variable. If the variable is an array the function prints the array in a format which displays the keys as well as values, a similar notation is used for objects. If the parameter $isStore is set to TRUE then the print_r() function will return a string containing the information which it is supposed to print. Below programs illustrate the print_r() function: Program 1: PHP <?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); ?> Output: Welcome to GeeksforGeeks 101 Array ( [0] => Welcome [1] => to [2] => GeeksforGeeks ) Program 2: PHP <?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; ?> Output: Array ( [0] => Welcome [1] => to [2] => GeeksforGeeks ) Reference: http://php.net/manual/en/function.print-r.php Comment More infoAdvertise with us Next Article PHP | print_r() Function S sid4321 Follow Improve Article Tags : Web Technologies PHP PHP-input-output Similar Reads PHP vprintf() function The vprintf() function in PHP is an inbuilt function which is used to display array values as a formatted string Display array values as a formatted string according to format it is work similar as printf() but accepts an array of arguments, in place of variables number of arguments. Returns the len 5 min read PHP vsprintf() Function The vsprintf() function in PHP is an inbuilt function and used to display array values as a formatted string. The array elements will be inserted at the percent (%) signs in the main string. Display array values as a formatted string according to its format and accepts an array argument in place of 5 min read PHP vfprintf() Function The vfprintf() function is an inbuilt function in PHP that is used to write formatted information to a stream, such as a file or the output screen. Syntax: vfprintf(resource $stream, string $format, array $values): Parameters: This function accepts three parameters that are described below. $stream: 2 min read PHP stristr() Function The stristr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-insensitive. Syntax : strist 2 min read PHP rtrim() Function The rtrim() function is a built-in function in PHP which removes whitespaces or other characters (if specified) from the right side of a string. Syntax:rtrim( $string, $charlist )Parameters: The function rtrim() accepts two parameters as shown in the above syntax. Out of these two parameters, one is 2 min read Like