Jump to content

Recommended Posts

Posted

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

Posted

$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.

Posted
$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.

Posted
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 :lol:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...