Skip to content

How to Append an Item to Array in PHP

How to Append an Item to Array in PHP. How do I append any element to end of the existing Array in PHP? This tutorial uses array_push() function.

Category
PHP
Versions & support
About PHP →

Question – How to Append an Item to Array in PHP. How do I append any element to end of the existing Array in PHP? How to push element to array in PHP?

This tutorial uses array_push() function to insert or append a new element to end of the Array.

PHP – Append Element to Array

The following example creates an initial array with two elements (as “black”,”blue”). After that add use array_push() function to append new element “white” to the array.

Output:

Array
(
    [0] => black
    [1] => blue
    [2] => white
)

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top