+ 2
I am confused with Increment and Decrement lesson of php course.Guys need help.....
Php Increment Decrement
4 Antworten
+ 3
Mohammad Shahzar There is two type of increment and decrement. One is Post increment/decrement and another is Pre increment/decrement.
In Pre increment/decrement first value will increment/decrement by 1 then assign to the variable.
In Post increment/decrement first assign the value then increase/decrease the value by 1.
So according to Your
++a is pre increment, --a is pre decrement
a++ is post increment, a-- is post decrement.
Let's take a example:
$a = 1;
$b = $a++; //here we will assign the value of a to b then increase the value by 1
So b will 1 and a will be 2
$c = 1;
$d = ++$c; //here first increase the value of c by 1 then assign to d
So d will be 2 and also c will be 2
Same for pre and post decrement
See here
https://code.sololearn.com/w91r4yofZ45l/?ref=app
+ 2
Mohammad Shahzar Can you explain in brief where you are getting problem. Increment and decrement is just use to increase and decrease the value by 1.
For example:
$num = 0;
$num++; //it's like $num = $num + 1;
echo $num; //will give 1
same for $num--; //it's like $num = $num - 1;
echo $num;// will give -1
+ 1
Thnx AJ Anant #G3 for your help
0
AJ Anant #G3
Can you please define it in bereif what are their differences with example:++a,a++ ,--a and a--