How to add a variable to an existing array in php

advertisements

I need to append a variable to an array . Please guide me if i go wrong in any line :

$arr= array(); // defines arr an empty array ?

$deposit=$_POST['amountdeposit']; // this is a variable i want to append to arr array.

// now array arr looks more a like to array("$deposit ") ?

and then i need to pass this array in a url .

When again there's a value in $_POST['amountdeposit'] it is again appended to this existing array.


Should be like with using []:

$arr   = array();
$arr[] = $_POST['amountdeposit'];

Output

array (size=n)
  0 => int 10
  1 => int 20
  2 => int 30
  n+ => ...