jjfletch Posted September 24, 2006 Share Posted September 24, 2006 When I print_r($_POST) to determine what's being posted from my form, I get this:[code=php:0]Array ( [name] => Array ( [0] => Joe [1] => [2] => [3] => [4] => [5] => ) [animal] => Array ( [0] => Dog [1] => Cat [2] => [3] => [4] => [5] => ) [submit] => Validez )[/code]Then, I array_combine to (duh) combine the arrays, and I get this:[code=php:0]Array ( [Joe] => Dog [] => )[/code]I'd like to get this:[code=php:0]Array ( [Joe] => Dog [] => Cat)[/code]Anyone know how I can accomplish this? Link to comment https://forums.phpfreaks.com/topic/21832-array_combine-modification/ Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 Hint - use pre tags around print_r(), it makes it much more legible.[code]echo '<pre>', print_r($_POST, true), '</pre>';[/code] Link to comment https://forums.phpfreaks.com/topic/21832-array_combine-modification/#findComment-97581 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 If I have[code]<?php$a = array (0 => 'Joe', 1 => ''); $b = array (0 => 'Dog', 1 => 'Cat');?>[/code]Then[code]<?php$c = array_combine($a, $b); ?>[/code]--> [pre]Array( [Joe] => Dog [] => Cat)[/pre] Link to comment https://forums.phpfreaks.com/topic/21832-array_combine-modification/#findComment-97584 Share on other sites More sharing options...
paul2463 Posted September 24, 2006 Share Posted September 24, 2006 the array_combine is doing what you asked of it, it is taking the keys from your name array and combinging it with the keys of the animals array, as you only have one element in your name array it will only combine it with one element from your animal array, the first one, which happens to be dog, so after all that it is doing exactly what it is meant to do....if you wish all the elements from one array to be joined with all the elements of another array then you need:-[code]$result = array_merge($array1, $array2);[/code]will result, when you print_r it[code]Array ( [0] => Joe [1] => Dog [2] => Cat ) [/code] Link to comment https://forums.phpfreaks.com/topic/21832-array_combine-modification/#findComment-97585 Share on other sites More sharing options...
Barand Posted September 24, 2006 Share Posted September 24, 2006 He is trying to combine, except where I get[pre]Array( [Joe] => Dog [] => Cat)[/pre]he gets[pre]Array( [Joe] => Dog [] => )[/pre] Link to comment https://forums.phpfreaks.com/topic/21832-array_combine-modification/#findComment-97587 Share on other sites More sharing options...
paul2463 Posted September 24, 2006 Share Posted September 24, 2006 same here Barand, when I run it I getArray ( [Joe] => Dog [] => Cat ) Link to comment https://forums.phpfreaks.com/topic/21832-array_combine-modification/#findComment-97596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.