DEV Community

웹학교
웹학교

Posted on

3 3

PHP에서 문자열을 표현할 때 ""과 ''이 항상 같을까?

일반적으로 PHP에서 문자열을 표현할 때 인용부호(" 또는 ')를 사용합니다.
그런데 그 결과가 항상 같으면 좋은데 가끔 차이가 있습니다.

'을 사용하면 ''안의 모든 것을 일반 텍스트로 처리합니다.

$age = 29;
$string = '내 나이는 $age 입니다.';
echo $string; // 결과 : 내 나이는 $age 입니다.
Enter fullscreen mode Exit fullscreen mode

"을 사용하면 ""안의 변수 보간을 하여 해당 변수를 반영하여 출력해 줍니다.

$age = 29;
$string = "내 나이는 $var 입니다.";
echo $string; // 결과 : 내 나이는 29 입니다.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay