Jump to content

Just some help understanding


dragonusthei

Recommended Posts

Hello

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\" /]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

$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:
[code]
if (isset($_GET['action']) {
   $action = $_GET['action'];
} else {
  $action = '';
}
[/code]

edit: andyb beated me
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.