skyer2000 Posted May 7, 2009 Share Posted May 7, 2009 I've pulled two strings from my database: keyid = (1,5,7) keyword = (foo1,foo2,foo3) I can convert them to their own arrays by using the explode function, however, the array is: array(0 => foo1, 1 => foo2, 2 => foo3); When I need it to match the keyid for each keyword: array(1 => foo1, 5 => foo2, 7 => foo3); How do I combine them like that? Link to comment https://forums.phpfreaks.com/topic/157225-solved-manipulating-array-data/ Share on other sites More sharing options...
Jibberish Posted May 7, 2009 Share Posted May 7, 2009 if you do something like <?php $keyid = '1,5,7'; $keyword = 'foo1,foo2,foo3'; $keyid_array = explode(',' , $keyid); $keyword_array = explode(',' , $keyword); $combined_array = array_combine($keyid_array, $keyword_array); print_r($combined_array); ?> I think that should give you the result you want. Link to comment https://forums.phpfreaks.com/topic/157225-solved-manipulating-array-data/#findComment-828458 Share on other sites More sharing options...
skyer2000 Posted May 7, 2009 Author Share Posted May 7, 2009 Thanks! I knew there had to be a function for that... Link to comment https://forums.phpfreaks.com/topic/157225-solved-manipulating-array-data/#findComment-828471 Share on other sites More sharing options...
messer Posted May 7, 2009 Share Posted May 7, 2009 and it works even with 3 arrays??? Link to comment https://forums.phpfreaks.com/topic/157225-solved-manipulating-array-data/#findComment-828489 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 Well the function works with 2 at a time, but you can apply it again and again for more. Link to comment https://forums.phpfreaks.com/topic/157225-solved-manipulating-array-data/#findComment-828491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.