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

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

Posted by: admin April 23, 2020 Leave a comment

Questions:

My print_r($view) function yields:

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.

How to&Answers:

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

Answer:

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).