php print_r 语句末尾的“1”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3771039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:02:38  来源:igfitidea点击:

What does "1" mean at the end of a php print_r statement?

php

提问by JDelage

My print_r($view)function yields:

我的print_r($view)函数产生:

View Object
(
    [viewArray:View:private] => Array
        (
            [title] => Projet JDelage
        )
)
1 <--------------

What does the "1" at the end mean? The PHP manual isn't very clear on how to parse the output of print_r.

末尾的“1”是什么意思?PHP 手册对如何解析print_r.

回答by Ionu? G. Stan

You probably have echo print_r($view). Remove the echoconstruct. And... what need do you have to parse its output? There are certainly much better ways to solve your problem.

你可能有echo print_r($view)。移除echo构造。而且……你需要什么来解析它的输出?当然有更好的方法来解决您的问题。

回答by Yuliy

print_r called with one argument (or with its second argument set to false), will echo the representation of its parameter to stdout. If it does this, it returns TRUE. Thus if you echo print_r($foo)you will print the contents of foo, followed by a string representation of the return value (which is 1).

使用一个参数(或将其第二个参数设置为 false)调用的 print_r 会将其参数的表示回显到标准输出。如果这样做,则返回 TRUE。因此,如果您echo print_r($foo)将打印 foo 的内容,然后是返回值的字符串表示(即 1)。