PDA

View Full Version : if variables



JohnN
June 6th, 2008, 12:42
long shot here. I know there's a way, however I haven't used it in a while and have forgotten how.

its basically an if statement inside a variable so its

$var = (code goes here)

sorry I'm s vague.

themoose
June 6th, 2008, 13:23
$var = (1==1)? "Why, yes it does" : "Not in this universe";
echo $var; // output: Why, yes it does

Tree
June 6th, 2008, 14:33
It's called the ternary operator (http://en.wikipedia.org/wiki/%3F:). PHP.net has a page (http://us3.php.net/language.operators.comparison) on it as well.

JohnN
June 6th, 2008, 15:46
Thank you both, mentok for the original and tree for the clarification.

I'd +rep you tree, but apparently I can't.

themoose
June 6th, 2008, 16:07
No problem. And I +rep'd Tree for you JohnN ;)

JohnN
June 6th, 2008, 20:13
No problem. And I +rep'd Tree for you JohnN ;)

thanks very much:) appreciated