By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

What is the use of question mark and colon (? and :) mean for in PHP?

P: 12
Please describe me what is the main use and difference between question mark and colon (? and :) in php ?

Expand|Select|Wrap|Line Numbers
  1. function get_all_state_details($state_id) 
  2.  {
  3.   $sql = "SELECT *  from  states  ";
  4.   $rows = $this->db->query($sql);
  5.   while ($record = $this->db->fetch_array($rows))
  6.     {
  7.    $strSelected = $record['state_id'] == $state_id ? 'selected = "selected"' : '';
  8.    $strState .= '<option value = "'.$record['state_id'].'" '.$strSelected.' >'.$record['state_name'].'</option>';
  9.    $i++;
  10.   } 
  11.   return $strState;
  12.  }
Feb 27 '12 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,349
It's an alternate form for if then else.
Feb 27 '12 #2

P: 93
it's comparison operator same as if...else condition...
Apr 16 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.