User Contributed Notes: array_push
anaik@bayou.uh.edu
09-Dec-1999 06:48
hi there:
HELP!! any one knows how to add elements to an array in version 3 ...i dont think i can use the array_push thing..and please make it simple to understand.
thanks
chuck@cyberstand.net
13-Dec-1999 09:38
$array[] = $var; works with php 3...
array_push will not create an array for you... The variable must already exist, and must be an array. Go with the old if you are not sure what your doing.
a
05-Jan-2000 05:12
Could someone tell me how to delete elements
from, or somehow wipe out an array in PHP 3.0 (can't use array_pop in this version...)? I need to reuse the array, but put less elements in. Any help would be terriffic.
-a
swo@hpinc.com
12-Jan-2000 09:03
It's possible to delete an array (at least in php 3) using "unset ($arrayname);" (without the quotes).
sheppard_norfleet@mail.crc.com
04-Feb-2000 01:26
How does one push a key value pair into a php3 array. This implementation seems logical, but it is unacceptable to PHP3 parser:
Array[] = "Name"=>AnotherArray;
this implementation is based on the example given in the user notes of the array function:
$users = array("djuan"=>array(....
If a discrete pair is (key,array) then one ought to be able to push a pair onto an array. This however does not seem to be the case with the php3 syntax.
Looking forward to an answer...
sheppard_norfleet@mail.crc.com
08-Feb-2000 09:14
I finally found the answer to the above question. If you want to push a key value pair onto an associative array. This is the "correct" syntax.
Array[$Key] = AnotherArray;
Hope this helps somebody.
unnikrishnan@gocubs.com
02-Mar-2000 03:32
If you want to add a element to a linear table (one dimensional) the traditional method is best.<pre>$array_name[]=$variable_name</pre>. On the other hand if you want to insert a <pre>($key,$val)</pre> into an array the easy way is <pre>$array_name[$key]=$val</pre>. Thats all.
luthra@eden.rutgers.edu
28-Mar-2000 10:14
is there one function in php, that can delete an element from an array and shift the rest of the elements up or down, so that there is no empty location in the array.
mahaharami@hotmail.com
28-Mar-2000 10:52
how do u use array_push to push an element onto a multidimensional array?
is there any other way??
scowboy79@yahoo.com
21-Apr-2000 03:43
Hi there,
Does anyone know how to add elements to an ALREADY EXISTING 2 dimentional array?
Regards,SC.
j.kase@privador.com
01-Jul-2000 01:38
I needed to use array_push with PHP3, and instead of array_push($array,$item) I used $array[count($array)] = $item, to add the last element. Works if you have number-based arrays (i.e elements are ordered).
jtb@getexo.nl
24-Jul-2000 09:50
Can someone help me with php3 ?
I've got this table with field productid and productdescription, now I want the user to see the productdescription and if selected it should return the value productid, this table is highly dynamic; How do I fill this array for a combo box ?!?
jonathan@netcreations.com
02-Aug-2000 01:32
This has already been asked but how do I push an element onto a two dimentional array in PHP4?
I tried <pre>array_push($array[Sub_array],element);</pre> to no avail.