我正在尝试创建一个嵌套数组,以便在网页中生成一个嵌套列表。
到目前为止,我已经设法获得以下内容:
Array
(
[2012] => Array
(
[Show 1] => Array
(
[0] => Class 1
)
[Show 2] => Array
(
[0] => Class 1
)
)
[2009] => Array
(
[Show 1] => Array
(
[0] => Class 1
)
)
[2008] => Array
(
[Show 1] => Array
(
[0] => Class 1
)
)
)
但是,我的实际结果每场演出超过 1 节课,所以应该如下所示:
[2012] => Array
(
[Show 1] => Array
(
[0] => Class 1
[1] => Class 2
[2] => Class 3
)
etc etc etc.
我已经做到了这一点,但不知道如何继续,以便每场演出不止一堂课。
我的代码如下:
$handlerresults = $db->query("SELECT SHOW_NAME, YEAR, CLASS_NAME FROM vwhandlerresults WHERE HANDLER_ID = $gethandlerid ORDER BY YEAR DESC");
$showname = '';
while($row = $handlerresults->fetch_array(MYSQLI_ASSOC)) {
$year = $row['YEAR'];
$show = $row['SHOW_NAME'];
$results[$year][$show] = array($row['CLASS_NAME']);
}
print_r($results);