section31 Posted January 3, 2004 Posted January 3, 2004 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] http://us4.php.net/manual/en/language.expressions.php Can Anyone help. Thanks, Dave Quote
Deverill Posted January 3, 2004 Posted January 3, 2004 $var++ will post increment the var by 1. $var += 3 will post increment the var by 3. $var + 3 will use the value 3 higher than the original. Your example of array[$var+3] should be fine. If you are totally stumped you could do $temp=$var+3 then use array[$temp] Hope it helps. Quote
vendlus Posted January 4, 2004 Posted January 4, 2004 $var++ will post increment the var by 1.$var += 3 will post increment the var by 3. $var + 3 will use the value 3 higher than the original. Your example of array[$var+3] should be fine. If you are totally stumped you could do $temp=$var+3 then use array[$temp] Hope it helps. Yeah, that's what I thought as well. So if $var is 5, then [$var+3] will evaluate as 8. But then $var should still be 5. Quote
section31 Posted January 4, 2004 Author Posted January 4, 2004 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.... here is something interesting. http://us4.php.net/manual/en/function.array-search.php Notice on example one the paramaters are flipped around...does php.net have a lot of mistakes? Quote
glassgorilla Posted January 4, 2004 Posted January 4, 2004 here is something interesting. http://us4.php.net/manual/en/function.array-search.php Notice on example one the paramaters are flipped around...does php.net have a lot of mistakes? 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 Quote
section31 Posted January 7, 2004 Author Posted January 7, 2004 You would think enough people would complain about it and it would be fixed. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.