⊗ppPmSFVSI 271 of 447 menu

Inserting Variables into Strings in PHP

In PHP, single and double quotes for strings are not entirely equivalent. The fact is that variables can be inserted into double-quoted strings - and the value of these variables will be substituted in their place.

Let's try it in practice. Suppose we have some variable:

<?php $str = 'aaa'; ?>

First, let's insert this variable into some string using the concatenation operation:

<?php $str = 'aaa'; echo 'xxx ' . $str . ' yyy'; ?>

Now let's change the quotes of our string to double quotes and insert the variable into it:

<?php $str = 'aaa'; echo "xxx $str yyy"; ?>

Simplify the following code:

<?php $name = 'user'; echo 'hello, ' . $name . '!'; ?>
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline