Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在echo函数中调用php函数_Php - Fatal编程技术网

在echo函数中调用php函数

在echo函数中调用php函数,php,Php,我是PHP新手,在获取输出时遇到问题。我必须声明并定义一个名为writeName的函数,并在其中回显:Avril。当我调用函数时,输出应该是我的名字是Avril 这是我的密码: <?php function writeName() { echo "Avril"; } echo "My name is" . writeName() . "<br>"; ?> 我的当前输出:avril我的名字是 我想要的输出:我的名字是Avril,你的函数正在进行输出。但你试图使用它,就

我是PHP新手,在获取输出时遇到问题。我必须声明并定义一个名为writeName的函数,并在其中回显:Avril。当我调用函数时,输出应该是我的名字是Avril

这是我的密码:

<?php
function writeName() {
  echo "Avril";
}
echo "My name is" . writeName() . "<br>";
?>
我的当前输出:avril我的名字是


我想要的输出:我的名字是Avril,你的函数正在进行输出。但你试图使用它,就好像它返回了艾薇儿的名字一样

执行顺序为:

parse writeName function
parse echo
    find string "my name is"
    execute function writeName
        output "Avril"
    find "<br>"
build echo with "my name is" and "br"
output "my name is <br>"
你应该拥有的是

function getName() {
   return "Avril";
}

echo "My name is " . getName() . "<br>";
这使得执行顺序:

parse echo
   find string "my name is"
   find function getName()
      execute getName()
         return "Avril"
    find string "Avril"
    find string "<br>"
    build string "My name is Avril<br>"
output string
回声艾薇儿;>返回Avril;
parse echo
   find string "my name is"
   find function getName()
      execute getName()
         return "Avril"
    find string "Avril"
    find string "<br>"
    build string "My name is Avril<br>"
output string