How to add elements to the end of an array in PHP

Topic: PHP / MySQL« Prev|Next »

Answer: Use the PHP array_push() function

You can use the PHP array_push() function to insert one or more elements or values at the end of an array. Check out the following example.

  • <?php
  • $skills = array("HTML5", "CSS3", "JavaScript");
  • // Append array with new items
  • array_push($skills, "jQuery", "PHP");
  • print_r($skills);
  • ?>

Related FAQ

Here are some more FAQ related to this topic:


Your Feedback:


We would love to hear from you! Please say something.