Home >Backend Development >PHP Tutorial >PHP prints out array contents and structure functions print_r and var_dump

PHP prints out array contents and structure functions print_r and var_dump

PHP中文网
PHP中文网Original
2016-07-28 08:29:581233browse

PHP prints out the array content and structure function print_r and var_dump

print_r() function

Example:

<?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 and the output is:

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 introduces the PHP print output array content and the structural functions print_r and var_dump, including the content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn