echo --输出一个或多个字符串或者数值变量
print_r --用于输出数组
var_dump --显示一个或多个表达式的结构信息,可输出字符串、数值、数组等的详细信息
注意 : 下面代码中 //后为输出结果
以一些实例来验证一下(基于PHP):
<?php
(1)三种方式输出字符串或者数字
$str="string";
echo $str; //string
print_r($str); //string
var_dump($str); //string 'string' (length=6)
$str=12;
echo $str; //12
print_r($str); //12
var_dump($str); // int 12
(2)三种方式输出一维数组
$array_1=array(
"username"=>"hanxin",
"age" =>"18"
);
echo $array_1; // error:Array to string conversion... Array
print_r($array_1); //Array (
[username] => hanxin
[age] => 18
)
var_dump($array_1); //array (size=2)
'username' => string 'hanxin' (length=6)
'age' => string '18' (length=2)
(3)三种方式输出多维数组
$array_2=array(
array(
"username"=>"hanxin",
"age" =>"18"),
array(
"username"=>"hanxin2",
"age" =>"19")
);
echo $array_2; //error:Array to string conversion .... Array
print_r($array_2); //Array (
[0] => Array (
[username] => hanxin
[age] => 18
)
[1] => Array (
[username] => hanxin2
[age] => 19
)
)
var_dump($array_2); //array (size=2)
0 => array (size=2)
'username' => string 'hanxin' (length=6)
'age' => string '18' (length=2)
1 => array (size=2)
'username' => string 'hanxin2' (length=7)
'age' => string '19' (length=2)