YouTip LogoYouTip

Php Print_R Function

# PHP print_r() Function [![Image 3: PHP Available Functions](#)PHP Available Functions](#) The **print_r()** function is used to print a variable in a way that is easier to understand. PHP Version: PHP 4, PHP 5, PHP 7 ### Syntax bool print_r ( mixed $expression [, bool $return ] ) Parameter Description: * $expression: The variable to be printed. If a string, integer, or float type variable is provided, the variable value itself will be printed. If an array is provided, the keys and elements will be displayed in a certain format. Objects are similar to arrays. * $return: Optional. If set to true, the result will not be output but assigned to a variable. If false (default), the result is output directly. ### Return Value Returns a string information that is easy to understand only if $return is set to **true**. ### Example ## Example 'apple', 'b' =>'banana', 'c' =>array('x','y','z')); print_r($a); ?> The output will be: Array( => apple => banana => Array ( => x => y => z )) Setting the $return parameter: ## Example 'monkey', 'foo' =>'bar', 'x' =>array('x', 'y', 'z')); $results = print_r($b, true); // $results contains the output of print_r?> The above example produces no output because the result is assigned to the $results variable. [![Image 4: PHP Available Functions](#)PHP Available Functions](#)
← Php Strval FunctionPhp Is_Resource Function β†’