How to append an item to array in php

In this article, We’ll see how to append an item to array in php.

we’ll use array_push() function because it’ll inserts one or more elements to the end of an array.




Insert “Node Js” and “Express Js” to the end of an array:

  $array = array("Java", "Php", "C++");
  array_push($array, "Node Js", "Express Js");
  echo "<pre>";
  print_r($array);
  echo "</pre>";

Output:

    Array
    (
        [0] => Java
        [1] => Php
        [2] => C++
        [3] => Node Js
        [4] => Express Js
    )

That’s it!. Please share your thoughts or suggestions in the comments below.

Posted in PHP

1 thought on “How to append an item to array in php

  1. This is really interesting, You’re a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your great post.
    Also, I have shared your web site in my social networks!

Leave a Reply

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