Reputation: 6150
I want to have a reference to an object in an array so I can change it later. In this case I am increasing the score of a particular user:
$guessing_user;
foreach($this->UUID_users[$UUID] as &$othr_user){
if($othr_user['user_object'] == $user){
$guessing_user=$othr_user;
break;
}
}
$guessing_user['score']+=10;
When I look in array at the original value ('score') it stays the same. I am probably missing something about references. Isn't the &
sign in foreach
enough?
Upvotes: 0
Views: 35
Reputation: 13843
try
$guessing_user = &$othr_user;
I think PHP makes a copy when you set $guessing_user
.
Upvotes: 2