Differences between PHP print and print_r functions
What is the difference between PHP's print and print_r ? These two seemingly similar things are actually completely different things. print itself is not a function. The function is used to output strings, the same as the echo function, while print_r is a function used to output arrays. , The following distinguishes the difference between the two according to the difference in grammar.
Basic syntax of PHP print and print_r functions
print_r (put the array to be output here, bool $return) print $string;
Explanation of grammatical differences
- Because print_r itself is a function, it must be written with parentheses to wrap the output array . For detailed usage, please refer to: PHP print_r output array .
- Print does not need parentheses at all, and outputs the string directly. If you want to use parentheses, you can also refer to the detailed syntax: PHP print output string .
// print example
$NewString ='Welcome to Wibibi.Have a good day.';
print $NewString;
// print_r example
$Arr = array ('apple','B' => ' banana');
print_r($Arr); // print the array for the first time
print_r($Arr, true); // will not print the array
?>
Array ( [A] => apple [B] => banana )
Post a Comment
0 Comments