Sorry to ask what must seem like a ridiculous question but I see a '?' used in a lot of code here and elsewhere but I can't seem to find a reference to its use in any of my books and obviously Googling '?' doesn't help either.
Can someone put me out of my misery and tell me what it's function or usage is?
Edit: obviously I don't mean the '?' in '<?php' - I'm not that new!
What is '?' for?: SOLVED
Moderator: General Moderators
What is '?' for?: SOLVED
Last edited by timsewell on Tue May 13, 2008 8:22 am, edited 1 time in total.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: What is '?' for?
I don't have an official technical definition however, I have always used ? to determine when variables and comparisons are being utilised.
However, "?" is also used in other programming languages. I remember using it with ColdFusion.
Hope this helps - I'm sure someone else will be able to offer a more definitive response
However, "?" is also used in other programming languages. I remember using it with ColdFusion.
Hope this helps - I'm sure someone else will be able to offer a more definitive response
Re: What is '?' for?
You probably mean the ternary operator (search for 'ternary' on the page)
It's an expression like (condition) ? expression1 : expression2, in which expression1 gets evaluated if condition is true, otherwise expression2.
For example:
It's an expression like (condition) ? expression1 : expression2, in which expression1 gets evaluated if condition is true, otherwise expression2.
For example:
Code: Select all
$a = 5;
$b = ($a > 3) ? 10 : 7;
// $b is now 10
// if $a would have not been >3 then $b would have been 7Re: What is '?' for?
Thanks very much. That makes sense to me now.