PHP Print_r () function

PHP

Syntax :
print_r ($variable, $isStore) 
Parameters : This function takes two parameters as shown in the syntax above and described below.
  • $variable : This parameter specifies the variable to be printed and is a required parameter.
  • $isStore : This is an optional parameter. This parameter is of a boolean type with a default value of FALSE and is used to store the output of the print_r() function in a variable, not to print it. If this parameter is set to TRUE, the print_r() function will return the output that is intended to be printed.
  • Return value : if the $variable is an integer or a number floating point, or string, function prints the value of the variable. If the variable is an array, the function prints the array in a format that displays keys and values, the same notation is used for objects. If $isStore is TRUE, the print_r() function will return a string containing the information it should print.The following programs illustrate the print_r() function:Program 1 : < tbody>  
    // PHP illustration program
    // print_r() function 
    // string variable $var1 = "Welcome to GeeksforGeeks" ;  
    // integer variable $var2 = 101;  
    // array variable $arr = array ( `0` = > " Welcome " , `1` = > "to" , `2` = > "GeeksforGeeks" );  
    // print variables print_r ( $var1 ); echo "" ; print_r ( $var2 ); echo "" ; print_r ( $arr );  
    ?>
    Output:
    Welcome to GeeksforGeeks 101 Array ([0] = > Welcome [1] = > to [2] = > GeeksforGeeks) 
    Program 2 :< / p>  
    // PHP illustration program print_r()
    // function when $isStore is set to true 
    // array variable $arr = array ( `0 ` = > " Welcome " , `1` = > "to" , `2` = > "GeeksforGeeks" );  
    // save the output of the print_r() function
    // in another variable $results = print_r ( $arr , true); echo $results ;  
    ?>
    Output:
    Array ([ 0] = > Welcome [1] = > to [2] = > GeeksforGeeks) 
    Link :
    http://php.net/manual/en/function.print-r.php



    Get Solution for free from DataCamp guru