Php 韩元';t转到else/elseif语句

Php 韩元';t转到else/elseif语句,php,Php,这里是Php新手,对本机Php购物车进行故障排除。由于某些原因,此代码不会转到elseif$item['type']>=7。尝试使用其他方法,但仍然没有成功。下面是条件语句的位。提前谢谢各位。另外,10多年前,一个家伙写了一篇文章,你能给出的任何关于如何使这段代码整洁的建议也是非常受欢迎的 我也重复了$item['type']的值,它的值确实大于7,以防你们认为这是问题所在 <?php if($item['type']<7) { //combinat

这里是Php新手,对本机Php购物车进行故障排除。由于某些原因,此代码不会转到elseif$item['type']>=7。尝试使用其他方法,但仍然没有成功。下面是条件语句的位。提前谢谢各位。另外,10多年前,一个家伙写了一篇文章,你能给出的任何关于如何使这段代码整洁的建议也是非常受欢迎的

我也重复了$item['type']的值,它的值确实大于7,以防你们认为这是问题所在

<?php if($item['type']<7)
        { 
        //combination
            $countChilli = 0;
            $surcharge = 0.0;
            echo 'Combination (';
            echo $comboTypes[$item['type']][$item['rice']]['name'];
            echo ')';
            ?> </div>
            <div class="comboItems not">

            <?php foreach($item['items'] as $ingredient)
            {
                echo $ingredient['itemName'].'<br />';
                if($ingredient['id']==133){ $countChilli++; }
            }
            if($countChilli==1)
            {
                if(count($item['items'])==1)
                {
                    $surcharge=300;//CHANGEED FROM 2.00
                }
                elseif(count($item['items'])==2)
                {
                    $surcharge=150;
                }
                else
                {
                    $surcharge=100;
                }
            }
            elseif($countChilli>1)
            {
                $surcharge=200;
            }
        }
        elseif($item['type']>=7)
        { //sauce only

            echo 'testing';
            echo $comboTypes[$item['type']][$item['rice']]['name'];
            ?> </div>
            <div class="comboItems sauce">
            <?php foreach($item['items'] as $ingredient)
            {
                echo $ingredient['itemName'].'<br />';
            }
        }

改变

elseif($item['type']>=7)

你也可能想要改变

if($item['type']<7)

if($item['type']更干净的代码实际上可以解决很多问题。另请参阅


您可以在那里施放:

if((int)$item['type']<7)

if((int)$item['type']是否将它与
$item['type']
作为数字或字符串进行比较?能否先执行
var_dump($item['type'])
?感谢各位的回答,但我想a已经解决了。这可能与if/Else语句无关。抱歉,我将删除该问题抱歉,我想对答案进行评论:/
if(intval($item['type'])<7)
<?php
if($item['type'] < 7)
{ 
    //combination
    $countChilli = 0;
    $surcharge = 0.0;
    echo 'Combination (';
    echo $comboTypes[$item['type']][$item['rice']]['name'];
    echo ')';
    echo '</div>
    <div class="comboItems not">';

    foreach($item['items'] as $ingredient)
    {
        echo $ingredient['itemName'].'<br />';
        if($ingredient['id'] === 133){ $countChilli++; }
    }

    if($countChilli === 1)
    {
        if(count($item['items']) === 1)
        {
            $surcharge = 300;//CHANGEED FROM 2.00
        }
        elseif(count($item['items']) === 2)
        {
            $surcharge = 150;
        }
        else
        {
            $surcharge = 100;
        }
    }
    elseif($countChilli > 1)
    {
        $surcharge = 200;
    }
}
else
{
    //sauce only
    echo 'testing';
    echo $comboTypes[$item['type']][$item['rice']]['name'];
    echo '</div>
    <div class="comboItems sauce">';

    foreach($item['items'] as $ingredient)
    {
        echo $ingredient['itemName'].'<br />';
    }
}
?>
if((int)$item['type']<7)
if(+$item['type']<7)