长乐王
长乐王

PHP调试输出:echo、print_r()和var_dump()

echo:输出一个或多个字符串。

print_r():打印关于变量的易于理解的信息(仅返回结果)。

var_dump():显示关于一个或多个表达式的结构信息(返回表达式的类型与值)。

$arr=array(
    array('a'=>'1','b'=>'2','c'=>'3'),
    array('a'=>'11','b'=>'22','c'=>'33'),
    array('a'=>'111','b'=>'222','c'=>'333')
);
$json=json_encode($arr);

echo $json;
#输出结果
/**
[{"a":"1","b":"2","c":"3"},{"a":"11","b":"22","c":"33"},{"a":"111","b":"222","c":"333"}]
**/

print_r($json);
#打印结果
/**
[{"a":"1","b":"2","c":"3"},{"a":"11","b":"22","c":"33"},{"a":"111","b":"222","c":"333"}]
**/

var_dump($json);
#返回结果
/**
string(88) "[{"a":"1","b":"2","c":"3"},{"a":"11","b":"22","c":"33"},{"a":"111","b":"222","c":"333"}]"
**/

print_r($arr);
#打印结果
/**
Array
(
    [0] => Array
        (
            [a] => 1
            [b] => 2
            [c] => 3
        )

    [1] => Array
        (
            [a] => 11
            [b] => 22
            [c] => 33
        )

    [2] => Array
        (
            [a] => 111
            [b] => 222
            [c] => 333
        )

)
**/

var_dump($arr);
#返回结果
/**
array(3)
{
    [0] => array(3)
    {
        ["a"] => string(1) "1"
        ["b"] => string(1) "2"
        ["c"] => string(1) "3"
    }
    [1] => array(3)
    {
        ["a"] => string(2) "11"
        ["b"] => string(2) "22"
        ["c"] => string(2) "33"
    }
    [2] => array(3)
    {
        ["a"] => string(3) "111"
        ["b"] => string(3) "222"
        ["c"] => string(3) "333"
    }
}
**/
本文番号: 长乐王 - 前端开发 - PHP调试输出:echo、print_r()和var_dump()

评论