PHP code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

PHP code

How this possible bellow output? <?php $str1=10; $str2=20; $str3="15"-$str1; echo $str1+$str2/$str3; ?> // output 14

30th Jan 2019, 11:29 AM
Gauhar Rahman Niazi
Gauhar Rahman Niazi  - avatar
3 Answers
+ 3
This is due to operator precedence, Gauhar Rahman Niazi . First, the echo line checks the division of $str2 and $str3 (20 divided by 5 = 4). Only then it sums this result with $str1 (10+4). Hope it helps, even if so long afterwards.
26th Feb 2019, 3:32 AM
D.R.
D.R. - avatar
+ 3
Thanks Abdul Moqueet
30th Jan 2019, 11:44 AM
Gauhar Rahman Niazi
Gauhar Rahman Niazi  - avatar
+ 2
Also the string "15" is implicitly converted to integer when doing calculations.
30th Jan 2019, 11:39 AM
Matthias
Matthias - avatar