dpcj32769 2015-06-14 08:16
浏览 123
已采纳

PHP - 返回和回显值的函数

I would like to create a function that both returns and echoes a value. But not the two together. Or return or echo. And I am looking for a beautiful way to do it. Almost all functions / class methods in my project must have this option.

I can pass to a function a bool value that indicates whether to echo or to return a value but it seems not so beautiful to me.

How, you think, it is better to implement this? Maybe a built-in option in PHP?

  • 写回答

1条回答 默认 最新

  • duanpuluan0480 2015-06-14 08:23
    关注

    Passing a boolean value is a good way to go, print_r does the same:

    mixed print_r ( mixed $expression [, bool $return = false ] )

    If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to TRUE, print_r() will return the information rather than print it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?