Jump to content

? within a line of PHP


Mark H
 Share

Recommended Posts

Hi all,I'm putting together a simple sign-in system at present, and the following code (which I have borrowed from a tutorial) I don't fully understand.

$page_mode = isset($POST['page_mode']) ? $POST['page_mode'] : ' ';

I understand the first part, but I don't understand the

? $POST[page_mode] : ' ' ;

I have looked again through the tutorials, but can't seem to find what the ? in the middle does?Thanks,Mark.

Link to comment
Share on other sites

The ?...: sequence is the ternary operator - it goes condition ? true-statement : false-statement, so in this case it means:

if (isset($POST['page_mode'])) {	$page_mode = $POST['page_mode'];} else {	$page_mode = ' ';}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...