Easy php Question about postincrement

windows

Guest
hm...I hate it when i get stuck in a jam while coding. How can i just use a variable+3 w/o postincrementing it in PHP. I just realized that php postincrements the variable automatically if u use this syntax $var+3. I don't want it to post increment, I just need it evaluated for an array i'm using. Ex. array[$var+3] <br /><br /><a href="http://us4.php.net/manual/en/language.expressions.php" target="_blank">http://us4.php.net/manual/en/language.expressions.php</a><br /><br />Can Anyone help. <br /><br />Thanks,<br />Dave<!--content-->
$var++ will post increment the var by 1.<br />$var += 3 will post increment the var by 3.<br />$var + 3 will use the value 3 higher than the original.<br /><br />Your example of array[$var+3] should be fine. If you are totally stumped you could do $temp=$var+3 then use array[$temp]<br /><br />Hope it helps.<!--content-->
<!--QuoteBegin-TCH-Jim+Jan 3 2004, 12:17 PM--><div class='quotetop'>QUOTE(TCH-Jim @ Jan 3 2004, 12:17 PM)</div><div class='quotemain'><!--QuoteEBegin-->$var++ will post increment the var by 1.<br />$var += 3 will post increment the var by 3.<br />$var + 3 will use the value 3 higher than the original.<br /><br />Your example of array[$var+3] should be fine. If you are totally stumped you could do $temp=$var+3 then use array[$temp]<br /><br />Hope it helps.<!--QuoteEnd--></div><!--QuoteEEnd--><br /> Yeah, that's what I thought as well.<br /><br />So if $var is 5, then [$var+3] will evaluate as 8. But then $var should still be 5.<!--content-->
Yeppers...you got it vendlus <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Thanks everyone, i realized it was a huge mistake on my part. It was one of my loops that was off by one that was screwing up my variables...next time i gotta read....<br /><br />here is something interesting. <br /><br /><a href="http://us4.php.net/manual/en/function.array-search.php" target="_blank">http://us4.php.net/manual/en/function.array-search.php</a><br /><br />Notice on example one the paramaters are flipped around...does php.net have a lot of mistakes?<!--content-->
<!--QuoteBegin-section31+Jan 3 2004, 10:41 PM--><div class='quotetop'>QUOTE(section31 @ Jan 3 2004, 10:41 PM)</div><div class='quotemain'><!--QuoteEBegin-->here is something interesting.  <br /><br /><a href="http://us4.php.net/manual/en/function.array-search.php" target="_blank">http://us4.php.net/manual/en/function.array-search.php</a><br /><br />Notice on example one the paramaters are flipped around...does php.net have a lot of mistakes?<!--QuoteEnd--></div><!--QuoteEEnd--><br />yes, the manual does have lots of errors. i actually just posted a note tonight on one of the pages that has an error. actually, it happens to be an array function too.. maybe the array guy was hammered when he wrote all those pages <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /><!--content-->
You would think enough people would complain about it and it would be fixed.<!--content-->
 
Back
Top