How does one add value to an array!

Hi,

I want to add values to an array, and I have followed the instructions of the Php Web site in this regard, but I am getting Error!

here is the simple sample array created:

$array_list = array();

$em1 = ‘d@s.com’;
$array_list = array_push($array_list, $em1);
echo ‘<p>’ . $array_list[0];

$em2 = ‘g@l.com’;
$array_list = array_push($array_list, $em2);
echo ‘<p>’ . $array_list[1];

But when I go to this Web page, to see the results, instead I get this Error:
Warning: array_push() [function.array-push]: First argument should be an array in /var/www/html/anoox.com/test/array_insert.php on line 23

What gives!

ThanX,

array_push() doesn’t need a variable to be referenced to it as it uses a call time reference to return the array with the new value(s), for example all you need to do is simply use.

$em1 = 'd@s.com';
array_push($array_list, $em1);
echo '<p>' . $array_list[0];

and it will work fine.

Ah, silly me!

Thank you :slight_smile:

It’s better to just assign values to array using this:
$array_list = $em1;
$array_list = $em2;
and so on…

it will just stick the value to the end of array. Probably a little easier to read this code