Php 如何将函数的返回值作为参数传递给另一个函数?

Php 如何将函数的返回值作为参数传递给另一个函数?,php,scope,arguments,function-calls,Php,Scope,Arguments,Function Calls,如何将一个函数返回的值传递给另一个函数 function myFunction(){ $a = "Hello World"; return $a; } function anotherFunction(????){ //how can I call the return value of myFunction() as parameter in this function? } 以下是方法: <?php function myFunction() {

如何将一个
函数
返回的值传递给另一个
函数

function myFunction(){
    $a = "Hello World";
    return $a;
}

function anotherFunction(????){
    //how can I call the return value of myFunction() as parameter in this function?
}
以下是方法:

<?php

function myFunction() {
    $a = "Hello World";

    return $a;
}

function anotherFunction( $yourvariable ) {
    //how can I call the return value of myFunction() as parameter in this function?
}

$myFunction = myFunction();

$anotherFunction = anotherFunction( $myFunction );
以下是方法:

<?php

function myFunction() {
    $a = "Hello World";

    return $a;
}

function anotherFunction( $yourvariable ) {
    //how can I call the return value of myFunction() as parameter in this function?
}

$myFunction = myFunction();

$anotherFunction = anotherFunction( $myFunction );


您可以使用此调用将return传递给另一个:

anotherFunction(myFunction());
您还需要声明另一个函数,如下所示:

function anotherFunction($val) {
    // your code here
}
这将把myFunction的返回值传递到$val参数中


希望这对你有帮助

您可以使用此调用将return传递给另一个:

anotherFunction(myFunction());
您还需要声明另一个函数,如下所示:

function anotherFunction($val) {
    // your code here
}
这将把myFunction的返回值传递到$val参数中

希望这对你有帮助

您有两个选择:

  • 将返回值保存在参数中,例如

    $value=myFunction();
    另一个函数($value)

  • 另一个函数(myFunction())
  • 你有两个选择:

  • 将返回值保存在参数中,例如

    $value=myFunction();
    另一个函数($value)

  • 另一个函数(myFunction())

  • 使用嵌套函数-function myFunction(){$a=“Hello World”另一个函数($a)/}使用嵌套函数-function myFunction(){$a=“Hello World”另一个函数($a)/}