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

PHP传递函数返回到另一个函数,php,function,return,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: //

我有一个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();

myfunction
将始终返回
“一”
。没有别的了。请纠正学生的行为

之后,如果您仍然希望一个函数的返回值在另一个函数中,只需调用它

function myfunction2() {
    $val = myfunction();
    return "something else";
}
试试这个:

function myfunction() {
   $array = array('one', 'two', 'three', 'four');
   $concat = '';
   foreach($array as $i) {
     $concat .= $i;
   }
   return $concat;
}

function myfunction2() {
   return myfunction() . "something else";
}
这将返回
onetwotreefoursomthing


这里的工作示例

在foreach中使用return听起来并不正确。因为它将返回一次并退出函数,所以它不会进入下一个数组项。我不完全理解你的问题。你能更清楚一点吗?输出应该是什么<代码>一个三个四个附加值??
function myfunction() {
   $array = array('one', 'two', 'three', 'four');
   $concat = '';
   foreach($array as $i) {
     $concat .= $i;
   }
   return $concat;
}

function myfunction2() {
   return myfunction() . "something else";
}