Jump to content

Can not find what the "&" does


larka06
Go to solution Solved by .josh,

Recommended Posts

I have some code working with arrays that I wrote but forgot what the "&" does to an array.  I know the results and it works but I can not remember nor can I seem to find it anywhere.  Probably not using the right search term. If some one can remind me It would be greatly appreciated.

Link to comment
Share on other sites

  • Solution

Would be more helpful if you posted the code that uses it. It can mean different things, depending on the context.

But most likely since you mentioned array, it was probably used to reference the original array. For example, if you are looping through an array using a foreach loop, and want to alter the value of the array, you'd do something like this:
 
 

$array = array(1,2,3,4,5);
foreach ($array as &$val) {
  $val++;
}

This will go through the whole array and increment each value by 1

Link to comment
Share on other sites

& can mean different things depending on the context it is used in. There is no array-specific meaning for it.

 

If used between two expressions then it would be treated as the bitwise AND operator

 

If used before a variable in an assignment or in a function parameter it would be the reference operator and cause a reference to the variable to be used rather than a copy of the variable.

 

If you want more specific information/explanation then you'll have to post the code in question so we can see how it is being used.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.