Jump to content

? within a line of PHP


Mark H

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

Archived

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

×
×
  • Create New...