Hi there,

the problem is that array_splice doesn't care about your string keys.
The manual states that array_splice($input, 0, 0, array($x, $y)) is identical
to array_unshift($input, $x, $y) which should make it clearer...

So, instead use array_merge or the + operator:

$locations1 = array_merge(array('Any' => 'Any'), $locations);
$locations2 = array('Any' => 'Any') + $locations;

Regards,
Maurice


Deepak Shrestha schrieb:
> 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
> 
> 

Reply via email to