Why does the switch below give me an “unexpected ‘>’” error? I Google’d for examples and found some that write it case > $numeral and others that write it case > = $numeral, but both give me the same error.
I want to display a centered image ($Img1C) if that image is more than 250 pixels wide, with the default image size floated to the right ($Img1R).
AFAIK, this can’t be done in a PHP switch. You can use if/else statements, and if you want slightly cleaner syntax, try the alternative syntax (e.g. if(statement): … endif; ). The switch structure is only for easily executing code based on known values of a statement/variable.
It can, but we shouldn’t encourage geosite to continue this pseudo-language he is creating where switch() trees control all program flow whether appropriate or not.
//3 lines with if()
$Img1st = $Img1R;
if ($Width1 > 250)
$Img1st = $Img1C;
//1 line with ternary operator
$Img1st = ($Width1 > 250) ? $Img1C : $Img1R;