开发者

Array yielding results AND an error at the same time

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 (li开发者_如何学Cve) that is working fine:

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

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


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' );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜