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.

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

报告相同问题?

悬赏问题

  • ¥15 SPSS分类模型实训题步骤
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么
  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。