Jump to content


Just some help understanding

  • Please log in to reply
2 replies to this topic

#1 dragonusthei

  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 05 June 2006 - 10:22 PM


I was just wondering if someone could explane some php for me

In the following:

$action = isset($_GET['action']) ? $_GET['action'] : '';

What would the ? mark do? what does a question mark do in PHP?

What would the : do what does : serve to do in PHP?

Thank you

[img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 05 June 2006 - 10:49 PM

ternary operator - faster than if then elses
tutorial explains - [a href=\"http://www.totallyphp.co.uk/tutorials/using_if_else_ternary_operators.htm\" target=\"_blank\"]http://www.totallyphp.co.uk/tutorials/usin...y_operators.htm[/a]
Legend has it that reading the manual never killed anyone.
My site

#3 .josh

  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 June 2006 - 10:52 PM

$action = isset($_GET['action']) ? $_GET['action'] : '';

$action = condition ? if condition is true, do this : if it is not true, do this;

basically you are setting the $action to a certain value, depending on whether $_GET['action'] exists or not. if it does, then it sets $action to $_GET['action']. if it is not, then it sets it to ''

it is the same thing as doing this:
if (isset($_GET['action']) {
   $action = $_GET['action'];
} else {
  $action = '';

edit: andyb beated me
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users