Home > Backend Development > PHP Tutorial > print_r为何多输出一个1?该怎么处理

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

WBOY
Release: 2016-06-13 13:44:19
Original
1321 people have browsed it

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


PHP code
<!--

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();



Copy after login


打印出 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);
<br><font color="#e78608">------解决方案--------------------</font><br>1 是print_r()函数的返回值 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template