print_r为何多输出一个1?
奇怪,第一次看到这样子。
- PHP code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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
——解决方案-本文来源gao.dai.ma.com搞@代*码#网搞代gaodaima码——————-
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()函数的返回值