Home >Backend Development >PHP Problem >How to print array in Php
php has two functions for printing arrays: print_r() function and var_dump() function
print_r() function
Example: (Recommended learning: PHP video tutorial)
<?php $arr_test = array(1, 2, 3); print_r($arr_test); ?>
Run this example output:
Array ( [0] => 1 [1] => 2 [2] => 3 )
var_dump() function
Example:
<?php $arr_test = array(1, 2, 3); var_dump($arr_test); ?>
Run this example output:
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
The var_dump() function is used the same as the print_r() function. However, the var_dump() function is more powerful than print_r(). It can print multiple variables at the same time and give the type information of the variables.
The above is the detailed content of How to print array in Php. For more information, please follow other related articles on the PHP Chinese website!