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
JavaScript Array push() The push() method adds new items to the end of an array. The push() method changes the length of the array. The push() method returns the new length.
Given two array arr1 and arr2 and the task is to append one array to another array. Using array_merge function: This function returns a new array after merging the two arrays. $arr1 = array ( "Geeks" , "g4g" );
The array_keys() function returns an array containing the keys.
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";
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With