PHP - 传递函数返回另一个函数

标签 php function return

我有一个返回值的 PHP 函数:

function myfunction() {
   $array = array('one', 'two', 'three', 'four');

   foreach($array as $i) {
     echo $i;
   }
}

还有另一个函数,我想从上面的函数传递返回值:

function myfunction2() {
   //how to send myfunction()'s output here? I mean:
   //echo 'onetwothreefour';
   return 'something additional';
}

我猜它看起来像 myfunction2(myfunction) 但我对 PHP 了解不多,所以无法让它工作。

最佳答案

是的,你只需要

return myFunction();

关于PHP - 传递函数返回另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9230236/

相关文章:

python - 为什么 Python 不打印返回值?

Javascript 返回冒号

php - 生成多个复选框并评估它们

php - do-while/while 中的分配没有按预期工作

c - 尝试在函数中使用 txt 文件时获取 "invalid type argument of ' ->' (have ' int')"

javascript - 为什么html调用js函数会出现html找不到变量错误?

c - 在 C 中将数组作为参数传递

javascript 返回函数返回未定义

php - 更新记录 dbal innodb silex

PHP 脚本不再写入数据库