PHP print_r output array

 PHP print_r is used to print out the contents of the array ( PHP Array ). The printing here is based on the vernacular of the function, which means to display it on the screen. You can also output the elements of the array one by one by simply using echo , but To output the entire Array at one time, it is better to use the print_r function for convenience.


PHP print_r syntax example

print_r (put the array to be output here, bool $return)


The front array in the grammatical structure must be placed. Of course it is meaningless to leave it. The bool $return at the back is only available after PHP 4.3.0. If set to true, print_r will not print the array on the page. Some are non-essential items, please see the following example.

PHP print_r implementation example
<?php
 $Arr = array ('A' =>'apple','B' =>'banana');
 print_r($Arr); // first print out the array
 print_r($Arr, true); / / Will not print the array
 $result=print_r($Arr, true);
 echo $result; // Print the array for the second time
?>
Output result: Array ([m] => monkey [foo] => bar) Array ([m] => monkey [foo] => bar) In the

example, an array $Arr is prepared at the beginning, and printed by print_r Then, we added true to print_r in the next line, and as a result, the array could not be printed. But when we save print_r($Arr, true); as a variable , and then print it directly through echo, it will appear on the page, so the final output result only presents two Arrays.

When using the wording $result=print_r($Arr, true);, $result contains the output result of print_r.

Post a Comment

0 Comments