print_r为何多输出一个1?
奇怪,第一次看到这样子。
php codeclass 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 codeecho print_r($var,true);
------解决方案--------------------
1 是print_r()函数的返回值
