Example 1 — Add Items to the End
Push two fruits onto a list and read the new size.
<?php
$fruits = ["apple"];
$count = array_push($fruits, "banana", "cherry");
echo implode(", ", $fruits), PHP_EOL;
echo $count, PHP_EOL; How It Works
- Start with one fruit. The array holds
apple. - Push two values.
bananaandcherrygo to the end. - Read the return value. It is the new number of items,
3. - Print the list. The original variable now has all three.

