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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arvind vohra
    New Member
    • Jan 2012
    • 12

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

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

    Code:
    function get_all_state_details($state_id) 
     {
      $sql = "SELECT *  from  states  ";
      $rows = $this->db->query($sql);
      while ($record = $this->db->fetch_array($rows))
    	{
       $strSelected = $record['state_id'] == $state_id ? 'selected = "selected"' : '';
       $strState .= '<option value = "'.$record['state_id'].'" '.$strSelected.' >'.$record['state_name'].'</option>';
       $i++;
      } 
      return $strState;
     }
    Last edited by Dormilich; Feb 28 '12, 06:25 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's an alternate form for if then else.

    Comment

    • Bharat383
      New Member
      • Aug 2011
      • 93

      #3
      it's comparison operator same as if...else condition...

      Comment

      Working...