...

View Full Version : writing a IF statement inside a array define



dawg
01-26-2012, 08:39 AM
$array13 [] = if($row_users['cat'] != "Main"){echo '-';} $row_users['message'];

so it hates the if statment, it works without the if statement, how do I make it work?

erde
01-26-2012, 08:43 AM
Try this:


$array13 [] = ($row_users['cat'] != "Main")?'-':$row_users['message'];

jmj001
01-26-2012, 08:49 AM
but without the ()

$array13[] = $row_users['cat'] != "Main" ? '-' : $row_users['message'];
although it may work with them... idk

Fou-Lu
01-26-2012, 02:39 PM
() are irrelevant in the evaluation block for ternaries. I typically use them since if you go more than 2 levels in depth without them its horrendously complex to read. Ie:


$array[] = $row_users['cat'] != "Main" ? $row_users['cat'] != "Category" ? $row_users['cat'] != "Test" ? 'Not one of these' : 'Is test' : 'Is category' : 'Is Main';

Not cool lol.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum