Jump to content

Archived

This topic is now archived and is closed to further replies.

dragonusthei

Just some help understanding

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\" /]

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.