Jump to content

[SOLVED] $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode']: '';


Recommended Posts

Ive tryed to understand this before but still not sure.

 

$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode']: '';

 

Ive never come across a tutorial with the use of ? and :

is it saying that if the $HTTP_POST_VARS['mode'] is set then that is what $mode equales and if not $mode equales a blank string?

 

Thanks if any one can help me understand this.

the ? ternary operator, and is pretty much an equivalent of if/else.

 

so your code converted to the if/else way would be:

 

<?php
if (isset($HTTP_POST_VARS['mode']))
{   
   $mode = $HTTP_POST_VARS['mode'];
}
else
{
   $mode = '';
}
?>

 

 

the bit before the ? is the condition. the next bit is the value to return if the condition is true, the last bit if the condition is false.

 

on another note, i'd recommend using $_POST instead of $HTTP_POST_VARS due to the latter being deprecated.

 

 

Hope that helps

Cheers

Mark

 

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.