PHP If / Else statement not working in While loop

前端 未结 1 1490
醉话见心
醉话见心 2020-12-12 00:35

I\'ve been working on this bit of code for about an hour and can\'t seem to figure out why it\'s not working. Does PHP allow If/Else statements within While loops? I\'ve tri

相关标签:
1条回答
  • 2020-12-12 01:15
    if ($layout = "vertical")   
    

    should be:

    if ($layout == "vertical")   
    

    Otherwise you are assinging a value to $layout of 'vertical' opposed to comparing it's value to see if it's equal to 'vertical'. That assignment will otherwise equal to true, reason the first part runs and the ELSE does not.

    One method I use to prevent accidents like this is to put the constant first such as:

    if ("vertical" == $layout)   
    

    That way if I miss the other = sign PHP will error, rather than assign the value erroneously.

    0 讨论(0)
提交回复
热议问题