【发布时间】:2013-09-04 09:54:31
【问题描述】:
我正在尝试使用和数组来打印出月份名称的前三个字母(我知道我可以使用 date() 来做到这一点,但我正在学习 PHP 中的数组,这似乎最简单)。 每次我运行底部的代码时,我都会收到下面的错误代码。
注意:未定义的偏移量:C:\Documents and Settings\Garry\My Documents\Dropbox\htdocs\Web-Apps\Locander2\Alpha\step2.php 第 17 行中的 8
只有在$monthArray[] 的索引部分输入 8 或 9 时才会出现此问题。
<?php
$monthArray = array(01 => "Jan",
02 => "Feb",
03 => "Mar",
04 => "Apr",
05 => "May",
06 => "Jun",
07 => "Jul",
08 => "Aug",
09 => "Sep",
10 => "Oct",
11 => "Nov",
12 => "Dec"
);
echo $monthArray[8];
?>
【问题讨论】:
-
删除 0 或调用 echo $monthArray[08];
-
你对每个号码都试过了吗? :)
-
对于所有
echo $monthArray[08];的回答,请在发布之前尝试您的代码。这将回显“Sep”而不是“Aug”。他在数组键中使用 0 做错了。向他解释为什么他不应该脱口而出你甚至没有花时间测试的东西。
标签: php arrays undefined offset