Jump to content

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


tallberg

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

 

Archived

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

×
×
  • 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.