difference between " quotes and '' quotes

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

    difference between " quotes and '' quotes

    please define me what is the main difference between double quotes and single quotes ?

    Code:
    $ans=20;
    
    echo "$ans";
    output 20
    
    echo '$ans';
    output $ans;
    
    if we can type
    
    
    function update_query($filename,$data,$where)
    	{
    		$sql= "UPDATE ".$filename." SET ";		
    		foreach ($data as $key=>$value)
    		{
    			$sql.=$key."='$value'";             
    		}
    		
    		$sql = $sql." WHERE ".$where;
    		echo " ".$sql."<br>"; die;
    		return $res = $this->query($sql);  
    	}

    please define me that line

    Code:
    $sql.=$key."='$value'";
    why we put "''" value in quotes .

    because "" is used for print the value

    and single quotes print the variable

    but why used here single quotes for print the value and how print the value

    That function is running condition.
    Last edited by Dormilich; Feb 9 '12, 06:41 AM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Single quotes don't print variables. Double quotes will expand variables. Hence the reason the string is surrounded by double quotes. The single quotes are for the benefit of the SQL engine. SQL requires strings to be surrounded by single quotes, which is why those single quotes surround the value.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      you'll find an in-depth explanation in the manual.

      Comment

      Working...