⊗ppPmBsMOP 18 of 447 menu

Priority of Mathematical Operations in PHP

Mathematical operations in PHP have the same priority as in regular mathematics. That is, multiplication and division are performed first, and only then addition and subtraction. In the following example, 2 will first be multiplied by 2 and then 3 will be added to the result:

<?php $a = 2 * 2 + 3; echo $a; // outputs 7 (result of 4 + 3) ?>

Without running the code, determine what will be displayed on the screen:

<?php $a = 5 + 5 * 3; echo $a; ?>

Without running the code, determine what will be displayed on the screen:

<?php $a = 5 + 5 * 3 + 3; echo $a; ?>

Without running the code, determine what will be displayed on the screen:

<?php $a = 8 / 2 + 2; echo $a; ?>

Without running the code, determine what will be displayed on the screen:

<?php $a = 8 + 2 / 2; echo $a; ?>
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