PHP - Append values to the end of an array

by
Jeremy Canfield |
Updated: February 12 2022
| PHP articles
If you are not familiar with arrays, check out our Getting Started article.
Let's say you have an array of fruit.
$fruit = array("apple", "banana", "orange");
array_push can be used to add values to the end of an array. In this example, grapes is added to the fruit array.
array_push($fruit, "grapes");
var_dump can be used to print the data structure of the array.
var_dump($fruit);
Which will show that grapes was appended to the array.
array(4) { [0]=> string(5) "apple" [1]=> string(6) "banana" [2]=> string(6) "orange" [3]=> string(6) "grapes" }
Did you find this article helpful?
If so, consider buying me a coffee over at