LoginSignup
2
2

More than 5 years have passed since last update.

シングルクォーテーションとダブルクォーテーションのちがい

Posted at

・ダブルクォーテーション  ・・・ 文字列中の変数を変数値に置換する

・シングルクォーテーション ・・・ 文字列中の変数を変数値に置換しない

  1. ダブルクォーテーションの場合 文字列中に変数を埋め込んでいた場合、変数内の値に置換されて表示されます。 $str = 'pen';

//「This is a pen.」 と表示される 
echo "This is a $str.";

  1. シングルクォーテーションの場合 文字列中に変数を埋め込んでいた場合でも、変数名がそのまま表示されます。

変数と同様に、特殊文字 (エスケープシーケンス)を記述してもそのまま表示されます。
$str = 'pen';

//「This is a $str.」 と表示される 
echo 'This is a $str.';

//「12345\n67890」 と表示される 
echo '12345\n67890';

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2