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

difference between " quotes and '' quotes

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

Expand|Select|Wrap|Line Numbers
  1. $ans=20;
  3. echo "$ans";
  4. output 20
  6. echo '$ans';
  7. output $ans;
  9. if we can type
  12. function update_query($filename,$data,$where)
  13.     {
  14.         $sql= "UPDATE ".$filename." SET ";        
  15.         foreach ($data as $key=>$value)
  16.         {
  17.             $sql.=$key."='$value'";             
  18.         }
  20.         $sql = $sql." WHERE ".$where;
  21.         echo " ".$sql."<br>"; die;
  22.         return $res = $this->query($sql);  
  23.     }

please define me that line

Expand|Select|Wrap|Line Numbers
  1. $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.
Feb 8 '12 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 10K+
P: 12,364
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.
Feb 8 '12 #2

Expert Mod 5K+
P: 8,639
you'll find an in-depth explanation in the manual.
Feb 9 '12 #3

Post your reply

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