Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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
Php 我想显示较大的数值变量,但它在第页中不显示任何内容_Php - Fatal编程技术网

Php 我想显示较大的数值变量,但它在第页中不显示任何内容

Php 我想显示较大的数值变量,但它在第页中不显示任何内容,php,Php,我想创建一个函数,该函数将两个数值变量作为参数,并返回两个变量中较大的一个,而不使用max函数,但它不会在页面中显示任何内容 很抱歉,我是php语言的初学者 <html> <head> <title>order</title> </head> <body> <?php function orderFunction($num1, $num2) {

我想创建一个函数,该函数将两个数值变量作为参数,并返回两个变量中较大的一个,而不使用max函数,但它不会在页面中显示任何内容

很抱歉,我是php语言的初学者

<html>
   <head>
      <title>order</title>
   </head>
   <body>
      <?php
         function orderFunction($num1, $num2) {
            if($num1>$num2){
               $num = $num1;    
               return $num;
            }else{
               $num = $num2;    
               return $num;
            }
            echo "the biggest is : $num";
         }
         orderFunction(10, 20);
      ?>
   </body>
</html>

秩序

orderFunction
在任何内容回显到页面之前返回值,而消费代码对该返回值不做任何处理。从函数中删除
echo
,并将其放入消费代码中:

echo "the biggest is : " . orderFunction(10, 20);

每个分支以
return$num结尾
echo
都在这两个后面。您可以认真地返回max($num1,$num2)作为函数的while主体,或者如果您确实不喜欢
max
(为什么?),那么
返回$num1>$num2$num1:$num2。根据David的回答,最好将回声移到函数外。