#native_company# #native_desc#
#native_cta#

Use of increment operator

By Vince Barwinski
on November 1, 2000

When I was first building my website, I had to sometimes increment integer variables, a very common programming task.

So if I wanted to increment an integer variable say “$year”, I would just
write “$year++”.

Now my point is this, when executing this operation in the C language, the
integer would become more positive, regardless of whether it was positive or
negative. So say -10 would become -9.

However, when I executed this operation in PHP4, a negative integer would
become more negative!!! So say -10 would become -11, the complete reverse
of what I experienced in the C language. So instead of writing the short
“$year++” I had to write “$year = $year + 1” and my code then executed
perfectly. I was dealing with years BC (Before Christ), which I assigned
as negative years and AD years which I of course assigned as positive years,
hence my discovery of this little anomaly.