PHP - Adding element to the end of array via array_push()

Introduction

To add an element to the end of an array, you can of course use the square bracket syntax mentioned previously.

You can use array_push(), which allows you to add multiple elements at once and tells you the new length of the array.

Demo

<?php

$authors = array("A","B","C","D");
echo array_push($authors,"Hardy","M")."\n"; // Displays"6"
print_r($authors);//  ww w .ja v a2s  .c om
?>

Result

Related Topic