首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

print_r为何多输出一个1?该怎么处理

2012-03-22 
print_r为何多输出一个1?奇怪,第一次看到这样子。PHP codeclass test{public $test array()function tes

print_r为何多输出一个1?
奇怪,第一次看到这样子。


PHP code
class test    {        public $test = array();                function test()        {            $this -> test[] = 'ok';        }        function _echo()        {            foreach ($this -> test as $val)                echo print_r($val);        }            }    $test = new test();    $test -> _echo();


打印出 ok1


[解决办法]
bool print_r ( mixed expression [, bool return] )
是函数当然会有返回值

对于你的应用,应写作
 echo print_r($val, 1);
[解决办法]
print_r
(PHP 4, PHP 5)
print_r -- 打印关于变量的易于理解的信息。 
描述
bool print_r ( mixed expression [, bool return] )
---------------------------------------------
既然print_r何必还要echo,如需要也得加上第二个参数

PHP code
echo print_r($var,true);
[解决办法]
1 是print_r()函数的返回值

热点排行