I'm having a hard time trying to update the values in my array. I made a simple example to illustrate this: the array contains names of players and the amount of points they have. After each round I want to update their points like this:
(which is not working)
$players = array (
array (
"id" => 0,
"name" => "John",
"points" => 0
),
array (
"id" => 1,
"name" => "Chris",
"points" => 0
),
array (
"id" => 2,
"name" => "Peter",
"points" => 0
),
array (
"id" => 3,
"name" => "Greg",
"points" => 0
),
);
$points0 = 10;
$points1 = 20;
$points2 = 30;
$points3 = 40;
$i = 0;
foreach ($players as $player) {
if ($player["id"] == $i) {
$player["points"] = ${"points".$i};
} $i++;
}
var_dump($players);
Must be something stupid, but I've been trying for hours and I just can't find it.
Thanks for the help!