php - Combine Multiple Foreach Results To One Variable String -
i have multiple foreach loops below, , i'm trying join 1 set of data inside 1 foreach, set of data in other foreach, can create 1 main variable post anywhere on page these values. thought way had setup below work, it's not. suggestions?
the variables have setup right now, data need collect $variable
foreach($result $row) { $sections[$row['section_id']][$row['question_id']] = $row; } foreach ($sections $key => $section) { $question_keys = array_keys($section); foreach ($question_keys $question_key) { if ($section[$question_key]["selection"] == 2) { } else { $variable .= '<div id="section-title">'.$section_details[$key].'</div>'; foreach ($section $key => $questions) { $variable .= '<div id="section-desc"> <div>'.$question_details[$key]["title"].'</div> <div>'.$question_details[$key]["desc"].'</div> <div>'.$selection_details[$questions["selection"]].'</div></div>'; } } } } the first $variable assigned section. sections nest questions. there can multiple sections nesting questions belong it. second $variable assigned questions nested underneath section. questions can multiple.
array output at $section level
array ( [2] => array ( [assessment_selection_id] => 97 [assessment_id] => 32 [section_id] => 2 [question_id] => 2 [selection] => 1 [timestamp] => 1368183565 ) [1] => array ( [assessment_selection_id] => 98 [assessment_id] => 32 [section_id] => 2 [question_id] => 1 [selection] => 3 [timestamp] => 1368183580 ) )
first of define $variable outside foreach loop. there issue looks inside structure of string assigning the $variable contains html elements, might not getting seen on browser.
Comments
Post a Comment