Please provide me the proper solution of this script with explanation:
$a = 5;
$c = $a-- + $a-- + --$a - --$a;
echo $c;
What will be the value of $c = 10; Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
++and--produce the same end result – incrementing or decrementing the variable – whether applied before of after the variable name, the difference comes when it is used as part of a larger statement.Consider this:
So you see, they produce the same end result –
$aget decremented by one. I’m sure this is what you were expecting.However:
In this example,
$ais still decremented after the operation, but the order in which the decrement happens and the value is used is different. For$a--the value is used before the decrement, and for--$athe value is used after.So for your example code: