Question on php | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 6

Question on php

$f=5; echo $f*$f++; Gives the output as 30, shouldn't it be 25 considering post increment is taking place?

16th Feb 2019, 6:32 PM
Ajeya Bhat
Ajeya Bhat - avatar
3 ответов
+ 4
like all programming language, there are rule of Operator Precedence: http://php.net/manual/en/language.operators.precedence.php so in this case, the first value load into memory is $f++ (equal 5) after this $f increment to 6, then the seconde operation is *. so since we have 5 in the memory, and $f = 6 so the output is 30.
17th Feb 2019, 11:43 PM
Elghozi Nasreddine
Elghozi Nasreddine - avatar
+ 4
hey Hello see the statements written is executed first before the echo prints its value by increasing By 1 so the increment is hidden but occurs as the statement is repeated unknowingly once for execution When it stays 5 and once for print when it gets covereted to 6 so it's in the whole 5*6=30 I hope u got it
17th Feb 2019, 12:22 PM
Preeti
Preeti - avatar
+ 3
//This will solve your problem, happy coding :) https://www.sololearn.com/learn/PHP/1826/
16th Feb 2019, 9:07 PM
Sudarshan Rai
Sudarshan Rai - avatar