Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PHP If / ElseIf statement not working [duplicate]

I have a really simple if / elseif statement that is not working how I want it to...

        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';
        }

If $title is set as New York or California then the script works, but if it is set as Chicago, Seattle or something else then it just displays 'This Is California'

What am I doing wrong?

like image 823
fightstarr20 Avatar asked Nov 30 '25 14:11

fightstarr20


1 Answers

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

like image 183
Koray Tugay Avatar answered Dec 03 '25 06:12

Koray Tugay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!