larka06 Posted February 10, 2014 Share Posted February 10, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286080-can-not-find-what-the-does/ Share on other sites More sharing options...
Solution .josh Posted February 10, 2014 Solution Share Posted February 10, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286080-can-not-find-what-the-does/#findComment-1468350 Share on other sites More sharing options...
kicken Posted February 10, 2014 Share Posted February 10, 2014 & 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. Quote Link to comment https://forums.phpfreaks.com/topic/286080-can-not-find-what-the-does/#findComment-1468351 Share on other sites More sharing options...
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.