'Twas brillig, and Deepak Shrestha at 11/02/09 07:56 did gyre and gimble:
Hi,

I got confused on why this is not working.

I have an array of locations stored in $location variable which is
fetched using fetchPairs(). I wanted to add and element "Any" => "Any"
at the beginning of this $location.

so my $locations is [from Zend_Degug::Dump($locations)]:
=================
array(3) {
    ["location1"] => string(9) "location1"
    ["location2"] => string(9) "location2"
    ["location3"] => string(9) "location3"
}
=================

I used:
=======
array_splice($locations, 0, 0, array("Any" => "Any"));

Expecting:
========
array(4) {
    ["Any"] => string(3) "Any"
    ["location1"] => string(9) "location1"
    ["location2"] => string(9) "location2"
    ["location3"] => string(9) "location3"
}
========

But I am getting:
========
array(4) {
    [0] => string(3) "Any"
    ["location1"] => string(9) "location1"
    ["location2"] => string(9) "location2"
    ["location3"] => string(9) "location3"
}
========

Why?

Thanks

If it's associative arrays you are working with, a simple:
  $loc2 = array('Any' => 'Any') + $locations;
will do the job.

Col



--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]

Reply via email to