I've always wondered what the ? is
Finally after years of php programming I now understand the use of the ? in a line of php code to define variables. It is called a tenerary operator and work like this.
QUESTION : ANSWER ? NO ANSWER
For example, in th examples, let's talk about the $normal variable that I set which will echo selected="selected" in the select menu if the user chose Normal mode in the form.
PHP Example: $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );
So in basic terms if the condition ($_GET['mode'] == 'normal') reutrns a TRUE result the variable $normal will be given the result of selected, otherwise a FALSE answer will assign $normal '' for no string.
I found this at phpfreaks while going through their excellent tutorial on building a weighted php/mysql search engine.
Comments, Pingbacks:
No Comments/Pingbacks for this post yet...
This post has 1 feedback awaiting moderation...
Leave a comment: