Jump to content

Archived

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

alexruimy

the ? and : thing...

Recommended Posts

I have code that looks like this:
[hr]
[code=php:0]$result  =  move_uploaded_file($temp_name, $file_path);
  if (!chmod($file_path,0777))
    $message = "change permission to 777 failed.";
  else
    $message = ($result)?"$file_name uploaded successfully." :
              "Something is wrong with uploading a file.";[/code]
[hr]
Just wondering what the ($result)? part is.  My guess is that it's equivalent to the following:
[hr]
[code=php:0]if ($result){
$message = "$file_name uploaded successfully.";
}
else {$message = "Something is wrong with uploading a file."};[/code]
[hr]

Am I on the right track? Can someone elaborate for me as to what this is?

Share this post


Link to post
Share on other sites
You're right. It's using the ternary operator. Think of it as an "if then else" construct.

Share this post


Link to post
Share on other sites
[url=http://us3.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary]Manual...[/url]

Share this post


Link to post
Share on other sites
Thanks both for the quick replies.

I would've tried to look it up but I wasn't sure of what to call it.

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.