unemployment Posted May 18, 2011 Share Posted May 18, 2011 How can I merge the array, but I keep in mind that I only need to merge userlocation and the usercity arrays. Current output... Array ( [0] => Array ( [0] => userlocation [1] => 19 ) [1] => Array ( [0] => credentials [1] => ) [2] => Array ( [0] => specialties [1] => ) [3] => Array ( [0] => usercity [1] => place1 ) ) Desired output... Array ( [0] => Array ( [0] => userlocation [1] => 19 [2] => usercity [3] => place1 ) [1] => Array ( [0] => credentials [1] => ) [2] => Array ( [0] => specialties [1] => ) ) How can this be done? The array is dynamic. Link to comment https://forums.phpfreaks.com/topic/236772-array-merge/ Share on other sites More sharing options...
wildteen88 Posted May 18, 2011 Share Posted May 18, 2011 Where are you getting this data from? Where are these arrays? Link to comment https://forums.phpfreaks.com/topic/236772-array-merge/#findComment-1217125 Share on other sites More sharing options...
unemployment Posted May 18, 2011 Author Share Posted May 18, 2011 Where are you getting this data from? Where are these arrays? The data is coming from a mysql query. if (strpos($news['action_id'], '~') !== FALSE) { $actions = explode('~', $news['action_id']); $action_details = explode('~', $news['details']); $information = array(); foreach ($actions as $k => $action) { $information[] = array($action, $action_details[$k]); } } Link to comment https://forums.phpfreaks.com/topic/236772-array-merge/#findComment-1217138 Share on other sites More sharing options...
wildteen88 Posted May 18, 2011 Share Posted May 18, 2011 Only guessing but maybe change $information[] = array($action, $action_details[$k]); to $information[$action][] = $action_details[$k]; If not what is $news['action_id'] and $news['details'] set to? Link to comment https://forums.phpfreaks.com/topic/236772-array-merge/#findComment-1217155 Share on other sites More sharing options...
unemployment Posted May 18, 2011 Author Share Posted May 18, 2011 Only guessing but maybe change $information[] = array($action, $action_details[$k]); to $information[$action][] = $action_details[$k]; If not what is $news['action_id'] and $news['details'] set to? $news['action_id'] is set to something like... userlocation~credentials~specialties~usercity $news['details'] is set to something like... 19~~~place1 That gives me this result which isn't exactly what I want. Array ( [userlocation] => Array ( [0] => Array ( [0] => userlocation [1] => 19 ) ) [credentials] => Array ( [0] => Array ( [0] => credentials [1] => ) ) [specialties] => Array ( [0] => Array ( [0] => specialties [1] => ) ) [usercity] => Array ( [0] => Array ( [0] => usercity [1] => place1 ) ) ) Link to comment https://forums.phpfreaks.com/topic/236772-array-merge/#findComment-1217161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.