Jump to content


Photo

the ? and : thing...


  • Please log in to reply
3 replies to this topic

#1 alexruimy

alexruimy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 09 August 2006 - 04:14 PM

I have code that looks like this:
 
$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.";
 
Just wondering what the ($result)? part is.  My guess is that it's equivalent to the following:
 
if ($result){
$message = "$file_name uploaded successfully.";
}
else {$message = "Something is wrong with uploading a file."};
 

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 August 2006 - 04:18 PM

You're right. It's using the ternary operator. Think of it as an "if then else" construct.
Legend has it that reading the manual never killed anyone.
My site

#3 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 09 August 2006 - 04:21 PM

Manual...
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#4 alexruimy

alexruimy
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 09 August 2006 - 04:23 PM

Thanks both for the quick replies.

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users