Page 1 of 1

Is there a easy way to push into associative array???

Posted: Thu Sep 01, 2005 6:41 pm
by raghavan20
I have a got an initially defined associative array.
I want to add elements to it (key, value pair) when required.
so looking for an equivalent of array_push() or any easiest way to do it.

ex:
initially
$tempArray = array("john"=>"millers")

after some time I want to add

"peter" => "wright"

Posted: Thu Sep 01, 2005 7:36 pm
by nielsene
Is there a reason why

Code: Select all

$tempAray["Peter"]="Wright";
wouldn't work?

Posted: Fri Sep 02, 2005 5:42 am
by raghavan20
I was totally unaware that would work.
Since I came from Java, I still dont understand fully the flexibility of PHP arrays and moreover I have not worked so much with associative arrays.
thanks again nielsene.

Posted: Fri Sep 02, 2005 7:19 am
by timvw
Might want to look at HashMap instead of array in Java if you want an equivalent for PHP arrays..

Posted: Fri Sep 02, 2005 7:30 am
by patrikG
raghavan20, when you're posting, please make sure(!!!) that you're using

Code: Select all

tags around code.