我有一個圖書館管理系統中的數組,在第一個索引上有一個用戶,在下一個索引上分配給該用戶的書籍,然後是有關像這樣分配的書籍的詳細信息。PHP:穿越多維陣列
這就是我需要以表格形式顯示
Array
(
[user] => Array
(
[0] => stdClass Object
(
[id] => 5
[name] =>
[email] => [email protected]
[password] => test
[role] =>
[status] => 1
)
)
[books] => Array
(
[0] => stdClass Object
(
[id] => 1
[user_id] => 5
[book_id] => 1
[date_issue] => 2016-07-24 00:00:00
[date_return] => 2016-07-25 00:00:00
)
[1] => stdClass Object
(
[id] => 2
[user_id] => 5
[book_id] => 2
[date_issue] => 2016-07-24 00:00:00
[date_return] => 2016-07-25 00:00:00
)
[2] => stdClass Object
(
[id] => 3
[user_id] => 5
[book_id] => 1
[date_issue] => 2016-07-25 00:00:00
[date_return] => 2016-07-25 00:00:00
)
)
[bookdata] => Array
(
[0] => Array
(
[0] => stdClass Object
(
[id] => 1
[title] => PHP Made Easy
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about php
)
)
[1] => Array
(
[0] => stdClass Object
(
[id] => 2
[title] => C++
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about c++
)
)
[2] => Array
(
[0] => stdClass Object
(
[id] => 1
[title] => PHP Made Easy
[author] => Dietel & Dietel
[serial_no] => 232323
[qty] => 9
[row_no] => 1
[col_no] => 2
[status] => 1
[category_id] => 1
[description] => This is a book about php
)
)
)
)
這是我嘗試解析這樣
foreach ($data as $key=> $value) {
echo $key[$value]->id;
}
錯誤我得到
嚴重性:警告
消息:非法偏移類型
文件名:觀點/ history.php
行號:4
請幫我解析這個陣列
你是什麼意思的「解析」?預期的結果是什麼?你的意思是「遍歷」而不是? – fantaghirocco
請發佈你想要的最終輸出 –
我的意思是我需要在html表中打印這些結果 – Sikander