0

$num=12; $num-- ; echo $num;

it should decrease value or num but first display the original value of num that is 12 is that so or decrement operater always first decrease then display , either it is pre-decrement or post-decrement

9th Apr 2017, 3:16 PM
Kajal
Kajal - avatar
4 Answers
+ 7
$num = 12; echo $num--; outputs 12 because in post decrement, value is returned and then decrement is done. $num = 12; echo --$num; outputs 11 because in pre decrement, decrement is done and then value is returned.
9th Apr 2017, 3:41 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 7
$num = 12; $num--; echo $num; Line 1 : Value of $num is 12. Line 2 : Value of $num becomes 11. Line 3 : Value of $num i.e. 11 is printed. In my previous post, I explained how pre decrement and post decrement work.
9th Apr 2017, 3:51 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
0
but a code in learning pages ans is given to 11
9th Apr 2017, 3:48 PM
Kajal
Kajal - avatar
0
then whats the difference in $num-- and --$num ? both are doing same work
9th Apr 2017, 4:10 PM
Kajal
Kajal - avatar