我正在爲我的一個網站創建日曆,我有一個數組如下。注意:未定義偏移量:0 - PHP - Foreach
array(2) {
[2017]=> array(1) {
["01"]=> array(1) {
[0]=> object(stdClass)#5374 (4) {
["ID"]=> string(3) "409"
["data"]=> string(10) "01/01/2017"
["post_title"]=> string(5) "TESTE"
["guid"]=> string(71) "?post_type=todos_os_cursos&p=409"
}
}
}
[2016]=> array(2) {
[10]=> array(2) {
[0]=> object(stdClass)#5974 (4) {
["ID"]=> string(3) "153"
["data"]=> string(10) "19/10/2016"
["post_title"]=> string(23) "Mundi Chef Professional"
["guid"]=> string(71) "?post_type=todos_os_cursos&p=153" }
[1]=> object(stdClass)#5977 (4) {
["ID"]=> string(3) "145"
["data"]=> string(10) "01/10/2016"
["post_title"]=> string(30) "Mundi Confeiteiro Professional"
["guid"]=> string(71) "?post_type=todos_os_cursos&p=145"
}
}
["09"]=> array(4) {
[0]=> object(stdClass)#5978 (4) {
["ID"]=> string(3) "153"
["data"]=> string(10) "30/09/2016"
["post_title"]=> string(23) "Mundi Chef Professional"
["guid"]=> string(71) "?post_type=todos_os_cursos&p=153"
}
}
}
[....]
我需要組織這個日曆。例如。
年 - 月 - - 項目 - 月 - - 項目
年[...]
但我沒有收到。每次嘗試訪問這些項目時都會遇到同樣的問題。注意:未定義偏移。
你應該表明導致未定義的偏移誤差的代碼。 *提示*錯誤信息告訴你錯誤發生在哪一行。包括有助於向讀者展示問題的相關代碼(即周圍循環)。 – Sherif
我真的很希望你確保當你訪問10個月以後,你仍然在使用字符串來訪問它們,因爲[array [9]'和array [「09」]']不一樣(http:// www .tehplayground.com /#iryv4NZhl)。只是關心你怎麼不把10當作一個字符串 –