You have a simple syntax error. You are forgetting to use the colon : at the end of your if and else statements which is necessary using PHP’s alternate syntax and you are including opening and closing braces {} which cannot be used with this syntax. You also need an endif and any time you have a PHP statement you must terminate it with a semi-colon ;.
You don’t have to use the alternate if syntax. What you have will do except when you close the php tags after the if block, what happens is you’re printing output before your “else”.
Be aware of oddities when dealing with 0 (zero) values in an array…
This script:
<?php
$array = array('testing',0,'name');
var_dump($array);
//this will return true
var_dump(in_array('foo', $array));
//this will return false
var_dump(in_array('foo', $array, TRUE));
?>
It seems in non strict mode, the 0 value in the array is evaluating to boolean FALSE and in_array returns TRUE. Use strict mode to work around this peculiarity.
This only seems to occur when there is an integer 0 in the array. A string ‘0’ will return FALSE for the first test above (at least in 5.2.6).
If you ever have the value 0 in your array, you could get unwanted results… so be sure to test for that.