Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altering objects that have been set equal

I'm setting an array equal to another array.

So let's say array B = array C.

Then, if I do operations on array B, changing it's values, does C also change?

I want to say absolutely not, but I'm having a brain fart and I feel like that what's happening in my code right now.

like image 646
DeadApe Avatar asked May 11 '26 20:05

DeadApe


1 Answers

When you assign one array to another array the array will hold the reference so if you change the value in one array then it will surely change the value of other.

like in your example array B = array C. B will hold the reference to array C. so any changes in array B will reflect in array C.

like image 97
Murli Avatar answered May 13 '26 10:05

Murli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!