Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the folowing code:

foreach($itz as $vz) { 
$muAt_val = $browser->getFieldByName($vz);
array_push_assoc($mAtArray, $vz, $mAt_val);              
} 

Which outputs:

[mAt[1701]] => Array ( [0] => 9378 [1] => 9379 )

But I would like to have it:

[mAt[1701]] => 9378 [mAt[1701]] => 9379

How can I do this?

//update A duplicate index of an array is not possible, i'm using an array for saving an form

 $browser->post($url, $parameters); // $parameters = the array

When I save the form by hand I get a post(firebug) with:

 mAt[1701] = 9378 
 mAt[1701] = 9379

This is not possible with an array, how can I make this work?

Thanks,

share|improve this question
2  
The expected output is unclear. Could you elaborate a little? –  geomagas Oct 30 '13 at 17:48
    
Your third code block isn't a valid array structure. If you just want it to print out in that format, it should be easy to do that. –  octern Oct 30 '13 at 17:50
    
I use the Simpletest browser to fill a form and save it. the form has multiselect which is mAt. The multiselect has all the same name "1701" but different value's "9379 & 9378". When saving the form I use $browser->post('url.html', $array); I'm a bit stuck now on how to format the multiselect array. –  Mark Oct 30 '13 at 19:14
add comment

1 Answer

don't use push, use

foreach($itz as $vz) { 
   $muAt_val = $browser->getFieldByName($vz);
   $mAtArray[$vz]= $mAt_val;              
} 
share|improve this answer
    
function array_push_assoc does this, custom function. –  Mark Oct 30 '13 at 19:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.