Reputation: 691
I'm having difficulty adding to the end of an array. Not sure how to do it. Please help.
$person = array();
$person = array("name"=>"tom", "age"=>20, "height"=>180);
How do I add to the end of an array? I want to add "weight"=>120 to the end of an existing array.
Thanks
Upvotes: 19
Views: 83662
Reputation: 163234
Since this is an associative array, just do:
$person['weight']=120;
For regular numerically indexed arrays, you can use array_push()
or $person []= "new value";
.
Upvotes: 40