Elseif condition is explicitly a boolean true but doesn't evaluate as true

I simply put elseif ( true ) {echo "Lorem ipsum dolor sit amet";} in my foreach loop and then expected the Latin statement to print but the condition never evaluates as true even though I explicitly set the condition to true. The foreach code involves a table named “urls” and I’m hoping there is no conflict because it could be a reserved word in CakePHP.

You presumably have an if that this goes after? If that first if is true, then its block will be executed, not the elseif.

This is the full code:


if (false) {echo "This text doesn't print out"}
elseif ( true ) {echo "So this text should print but it doesn't" ;}

Is that really the exact code? When I try to run that, I get an error because there’s no ; at the end of the first echo statement. So either this isn’t really the code, or you’re developing with error reporting turned off for some reason, and refusing to accept the help that PHP wants to give you with nice error messages.

I have debug set to true in my app_local.php file and errorLevel set to E_ALL in my app.php file but no log entries were made for the requests.
I see what’s happening now. It evaluates correctly for the one page where there is something to loop over but it doesn’t work on the other pages where the foreach statement has nothing to loop over. I took the elseif statement out of the foreach loop and made it an if statement and now it’s all working.

if statements only gets the TRUE result

if(true){
echo “So this text should print but it doesn’t”;
}else{
echo “This text doesn’t print out”;
}

it should be like this

For that reason you should send the whole relevant code section. Your code doesn’t give any hint of an enclosing foreach loop.