⊗ppPmArFl 63 of 447 menu

Filling Arrays in PHP

It is not necessary to add elements to an array immediately at the moment of its declaration. You can first declare this array as empty, and then add the necessary elements to it, like this:

<?php $arr = []; // create an empty array $arr[] = 'a'; // element will be added to key 0 $arr[] = 'b'; // element will be added to key 1 $arr[] = 'c'; // element will be added to key 2 var_dump($arr); // will output ['a', 'b', 'c'] ?>

The array does not necessarily have to be initially empty - it may already contain something, but we can still add new elements:

<?php $arr = ['a', 'b', 'c']; // declare an array with elements $arr[] = 'd'; // element will be added to key 3 $arr[] = 'e'; // element will be added to key 4 var_dump($arr); // will output ['a', 'b', 'c', 'd', 'e'] ?>

Let an empty array be given:

<?php $arr = []; ?>

Using the described method, fill this array with elements with values 1, 2, 3, 4 and 5.

Let such an array be given:

<?php $arr = [1, 2, 3]; ?>

Add elements 4 and 5 to its end.

bydeenesfrptru