Jump to content

Can not find what the "&" does


larka06

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
https://forums.phpfreaks.com/topic/286080-can-not-find-what-the-does/
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

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