I have an existing array. I need to use array_push, or similar, to add a value onto the end of an array and assign it.
Code: http://pastebin.com/tNg7gZ91
array_push($playerHolo, 'player' => 'UsernameHere'); //invalid syntax (the =>)
var_dump($playerHolo);
I'm trying to add the value "player" and assign the string "UsernameHere" to it.
Other Information
array_push($playerHolo['1'], array('player' => 'UsernameHere'));
Displays
http://pastebin.com/GTDe8Ex9
Suggestions?
You can do this in 2 ways:
array_push($playerHolo, array('player' => 'UsernameHere'));
or
$playerHolo['player'] = 'UsernameHere';
The second parameter must be an array using valid array syntax if it is an associative array:
array_push($this->playerHolo, array('player' => 'UsernameHere'));
array_push($this->playerHolo, ['player' => 'UsernameHere']);
But why don't you just use a simple assignment?
$this->playerHolo['player'] = 'UsernameHere';
You'll notice I used $this->playerHolo
. This is because you are also using the wrong syntax for accessing class member variables. This will save you from the next error you will encounter.