数组同时产生结果和错误

发布于 2024-11-14 15:47:17 字数 900 浏览 2 评论 0原文

这是在我的主网站上运行的,所以当我正在放入图像时,它决定不工作。正如您将看到的,它产生的错误是幻影,但它会停止执行。我所做的只是提取月份,而不考虑评论,这不是本期的主题。 watch:(它可以是任何数组 - 记住它的实时工作)

$date = "2011-06-06 15:22:30";

$date = explode(" ",$date);     //splits time and date
echo $date[0]."<br/>"; // prints 2011-06-06

$date = explode("-",trim($date[0]));  //split ymd
echo $date[1]."<br/>";  // prints 06 *** no error here

$num = $date[1]; // now this doesnt work??!!??
echo "num: ".$date[1]; // prints 06 AND Undefined offset: 1 in....

问题:如何 echo "num: ".$date[1]; 产生正确的结果并同时具有未定义的偏移量?我在本地完成工作(当然),然后一旦工作我就上传它。但在我弄清楚为什么这个数组如此糟糕之前,我无法上传我的新作品!

这是谜题。这个确切的代码运行完美。我在完全不同的页面上添加图像。上面的代码与我正在做的工作 150% 无关,它只是不起作用。

运行良好的原始代码(实时):

$date = explode(" ",$date);     //splits time and date
$date = explode("-",$date[0]);  //split ymd

$date[1] = $month[$date[1]];
return $date;

this is working on my main site, so while i was working with putting images in, it decided not to work. as you will see, the errors it produces are phantoms, yet it halts execution. All I am doing is extracting the MONTH regardless of comments, its is not the topic of this issue. watch: (it could be any array - remember its working live)

$date = "2011-06-06 15:22:30";

$date = explode(" ",$date);     //splits time and date
echo $date[0]."<br/>"; // prints 2011-06-06

$date = explode("-",trim($date[0]));  //split ymd
echo $date[1]."<br/>";  // prints 06 *** no error here

$num = $date[1]; // now this doesnt work??!!??
echo "num: ".$date[1]; // prints 06 AND Undefined offset: 1 in....

question: how can echo "num: ".$date[1]; yield a correct result AND have an undefined offset at the same time? I do my work locally (of course) then once working I upload it. But I can't upload my new work until I figure out why this array is being a stinker!

here is the puzzler. this exact code is working live perfect. I was adding images on a completely different page. the code above is 150% non related to the work I am doing, it just is not working.

original code (live) that is working fine:

$date = explode(" ",$date);     //splits time and date
$date = explode("-",$date[0]);  //split ymd

$date[1] = $month[$date[1]];
return $date;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美不过初阳 2024-11-21 15:47:17

该代码对我来说效果很好,您确定该通知实际上来自该行吗?也就是说,下面的代码将完成相同的任务,但是(非常)容易:

<?php
$date = new Datetime( "2011-06-06 15:22:30" ); 
echo $date->format( 'm' );

That code works fine for me, are you sure the notice is actually from that line? That said, the following code will accomplish the same, but (a heck of a lot) easier:

<?php
$date = new Datetime( "2011-06-06 15:22:30" ); 
echo $date->format( 'm' );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文