Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»How to Append an Item to Array in PHP

    How to Append an Item to Array in PHP

    By RahulJuly 23, 20181 Min Read

    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?

    Advertisement

    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.

    1
    2
    3
    4
    5
    6
    7
    <?php
      $arr = array("black","blue");
      array_push($arr, "white");
     
      //View final array
      print_r($arr);
    ?>

    Output:

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

    PHP push string
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    PHP Arrays: A Beginner’s Guide

    Running Laravel Queue Worker as a Systemd Service

    How to Change PHP Session Timeout

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.