1

having problems using the text concatenation with the '->' operator in PHP. I cant seem to get the syntax right for $playerArray[$x] = $players->$p . $x;

all this code should do is step through the 'Players' JSON object and return the values from players 1 - 15

$playerArray = array();
    $p = "Player_";
    for ($x = 0; $x < 15; $x++) {
        $playerArray[$x] = $players->$p . $x;
        // insert into database the above 
    }

Here is the json object im trying to get values from.

enter image description here

Chris Mowbray
  • 295
  • 1
  • 3
  • 15

1 Answers1

1

Are you able to refer to the $players object using array notation, similar to how you would refer to the object in Javascript?

$playerArray = array();
    $p = "Player_";
    for ($x = 0; $x < 15; $x++) {
        $playerArray[$x] = $players[$p . $x];
        // insert into database the above 
    }
Tom Haws
  • 1,322
  • 1
  • 11
  • 23