Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»How to Append an Item to Array in PHP

    How to Append an Item to Array in PHP

    RahulBy RahulJuly 22, 20181 Min ReadUpdated:July 23, 2018

    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.

    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
    Previous ArticleHow to Reset Gnome Desktop on Ubuntu 18.04 Bionic
    Next Article How to Append an Item to Array in JavaScript

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How to Replace String in JavaScript

    Updated:June 13, 20222 Mins Read

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:June 19, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04

    Updated:June 28, 20225 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    • What is the /etc/nsswitch.conf file in Linux
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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