Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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_If Statement_While Loop - Fatal编程技术网

php+检查变量值是否在两个整数之间

php+检查变量值是否在两个整数之间,php,if-statement,while-loop,Php,If Statement,While Loop,我是新手,我认为我的if-else结构存在一些问题,但我无法理解问题的实质 我正在努力做到以下几点: <?php $num = 1; while($num <=10) { if ($num < 4) { print $num . " is less than 4 /"; } elseif ($num = 4) { print $num . " is just 4 /"; } elseif (($n

我是新手,我认为我的if-else结构存在一些问题,但我无法理解问题的实质

我正在努力做到以下几点:

<?php

$num = 1; 

while($num <=10)
{
    if ($num < 4)
    {
    print $num . " is less than 4 /";
    } 
    elseif ($num = 4)
    {
    print $num . " is just 4 /";
    } 
    elseif (($num > 4) && ($num < 10))
    {
    print $num . " is more than 4 and less than 10 /";
    } 
    elseif ($num = 10)
    {
    print $num . " is just 10 /";
    } 

 $num++; 

}
?>

我有几个小时的时间,所以我最后决定问。
任何帮助都将不胜感激!提前Ty阅读。

如果使用赋值运算符“=”,请使用条件运算符

<?php

$num = 1; 

    while($num <=10)
    {
        if ($num < 4)
        {
        print $num . " is less than 4 /";
        } 
        elseif ($num == 4)
        {
        print $num . " is just 4 /";
        } 
        elseif (($num > 4) && ($num < 10))
        {
        print $num . " is more than 4 and less than 10 /";
        } 
        elseif ($num == 10)
        {
        print $num . " is just 10 /";
        } 

     $num++; 

    }
?>

在elseif语句中,必须使用==而不是=

例如:elseif$num==4而不是elseif$num=4

<>你也可以考虑使用一个语句。
祝你好运

在if条件下,您需要比较变量。但您使用的是赋值运算符

请尝试这段代码


4&&$numWhat是预期的输出?=是赋值运算符,您可能希望使用比较运算符==OMG TY!我真是个笨蛋。。。我完全忘记了那件事。问题现已解决=因为它与主题无关,我是否应该删除它?是的!我的错。感谢您提供有关开关功能的提示。我不知道,它似乎正是我要用的东西。