Simple PHP If / ElseIf statement not working

This question already has an answer here:

  • The 3 different equals 4 answers

  • You are using = instead of == for the last cases.

    This will always be true since this is an assignation.

    Replace those by == and you're good to go.


    Careful with = and == . I think that is the problem.


    if ( $title == 'New York' )
            {
            echo 'This is New York';
            }
            elseif ( $title == 'California' )
            {
            echo 'This Is California';
            }
            else if ($title == "Chicago" )
            {
            echo 'This is Chicago';
            }
            else if ($title == "Seattle" )
            {
            echo 'This is Seattle';
            }
            else
            {
            echo 'No Match Found';
            }
    

    you have to be careful for == because = will not work properly in if condition for comparison every time

    use == for string and === if numeric

    链接地址: http://www.djcxy.com/p/58456.html

    上一篇: JavaScript / Jquery中“===”的含义是什么?

    下一篇: 简单的PHP如果/ ElseIf语句不起作用