Ty44ler Posted December 4, 2012 Share Posted December 4, 2012 I have a 1 dimensional array from a database output that I need to have in a multidimensional array ($tasks): array 0 => array 'sr_id' => string '4902367' (length=7) 'description' => string 'GLS Jersey Mikes Installation Checklist' (length=39) 'due_date' => string '2012-01-07 23:24:00' (length=19) 'sr_fe_task_id' => string '220958' (length=6) 1 => array 'sr_id' => string '4902367' (length=7) 'description' => string 'Please submit your pictures of the installation area before any work was performed.' (length=83) 'due_date' => string '2012-01-07 23:24:00' (length=19) 'sr_fe_task_id' => string '220959' (length=6) 2 => array 'sr_id' => string '4902367' (length=7) 'description' => string 'Please submit your pictures of the installation area after all work was completed.' (length=82) 'due_date' => string '2012-01-07 23:24:00' (length=19) 'sr_fe_task_id' => string '220960' (length=6) 3 => array 'sr_id' => string '4903303' (length=7) 'description' => string 'Upload pictures of colored patch cables connected to back of router.' (length=116) 'due_date' => string '2012-01-07 23:31:00' (length=19) 'sr_fe_task_id' => string '220961' (length=6) 4 => array 'sr_id' => string '4899664' (length=7) 'description' => string 'Please upload all pictures taken on site.' (length=41) 'due_date' => string '2012-01-17 17:33:00' (length=19) 'sr_fe_task_id' => string '222839' (length=6) Each sr_id may have more than one task under it and each task has a due_date and description under it, but I'm having trouble getting the descriptions and due_dates under each task: ['sr_id'] =>4902367 ['sr_fe_task_id'] => 220958 ['description']=> "GLS Jersey Mikes Installation Checklist" ['due_date']=> '2011-12-08 17:50:00' ['sr_fe_task_id'] => 220959 ['description']=> "Pleease submit your pictures of the installation area." ['due_date']=> '2012-01-07 23:24:00' ['sr_id'] =>4903303 ['sr_fe_task_id'] => 220961 ['description']=> "Upload pictures of colored patch cables connected to back of router." ['due_date']=> '2012-01-07 23:31:00' I've got it to where each sr_id is listed along with all the tasks underneath of them, but can't get it to where each task has the description and due date under it: for ($i=0; $i<COUNT($tasks); $i++){ $task_list[$tasks[$i]['sr_id']]['task_id'][$tasks[$i]['sr_fe_task_id']] =$tasks[$i]['sr_fe_task_id']; foreach ($task_list[$tasks[$i]['sr_id']]['task_id'] as $v){ $task_list[$tasks[$i]['sr_id']]['task_id'][$v][$tasks[$i]['due_date']]; } } Quote Link to comment https://forums.phpfreaks.com/topic/271600-creating-multidimensial-array-from-db-output/ Share on other sites More sharing options...
Ty44ler Posted December 4, 2012 Author Share Posted December 4, 2012 Solved: foreach ($tasks as $task) { $task_list[$task['sr_id']]['task_id'][$task['sr_fe_task_id']] = array(); $task_list[$task['sr_id']]['task_id'][$task['sr_fe_task_id']]['due_date'] = $task['due_date']; $task_list[$task['sr_id']]['task_id'][$task['sr_fe_task_id']]['description'] = $task['description']; } Quote Link to comment https://forums.phpfreaks.com/topic/271600-creating-multidimensial-array-from-db-output/#findComment-1397534 Share on other sites More sharing options...
Christian F. Posted December 4, 2012 Share Posted December 4, 2012 You don't actually need this line, since it is an array already: $task_list[$task['sr_id']]['task_id'][$task['sr_fe_task_id']] = array(); Quote Link to comment https://forums.phpfreaks.com/topic/271600-creating-multidimensial-array-from-db-output/#findComment-1397576 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.