⊗ppPmCdBO 92 of 447 menu

Optionality of Curly Braces in Conditions in PHP

In case there is only one expression inside the curly braces of if or else, these curly braces can be omitted. Let's say, for example, we have this code with all the braces:

<?php if ($test == 0) { echo '+++'; } else { echo '---'; } ?>

It can be shortened like this:

<?php if ($test == 0) echo '+++'; else echo '---'; ?>

Or like this:

<?php if ($test == 0) { echo '+++'; } else echo '---'; ?>

You can also remove all braces, but format everything not in a line, but like this:

<?php if ($test == 0) echo '+++'; else echo '---'; ?>

Rewrite the following code in a shortened form:

<?php if ($test == 0) { echo 'yes'; } else { echo 'no'; } ?>

Rewrite the following code in a shortened form:

<?php if ($test == 0) { echo 'yes'; } ?>
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