2015-08-26 118 views
0

我有一個數組,它是:PHP的strtotime奇怪的偏移誤差

array:2 [▼ 
    0 => true 
    1 => "2015-08-26 08:42:51" 
] 

我可以訪問$arr[1] = "2015-08-26 08:42:51" - 但是,如果我這樣做:strtotime($arr[1])我得到:未定義抵消:1

什麼可能會導致這問題?在位置1設置的陣列..

編輯:

public static function in_date_range($needle, $date_from, $date_to) 
    { 
     $start_date = strtotime($needle[1]); 
    } 

而且我把它從:

$date = $status['resource_completed']; 

if(Helper::in_date_range($date, 
    strtotime($from_date"), 
    strtotime($to_dat))) 
{ 

} 

其中:

$date = array:2 [▼ 
    0 => true 
    1 => "2015-08-26 08:42:51" 
] 
+1

可否請你展示下這個現象發生的代碼? –

+0

你所展示的對我來說工作得很好。向我們展示更多代碼 – Hearner

+0

您確定您擁有一切正確的名字嗎?因爲它適合我。 – Smuuf

回答

0

您的的聲明語法數組無效。

你應該聲明數組是這樣的: -

$date = array(
    '0' => true, 
    '1' => "2015-08-26 08:42:51" 
); 
+0

不是數組聲明,是從Symfony2「dump」組件轉儲的; –

+0

由於op表示數組被定義爲這樣,所以這是一個合法的答案。雖然可能是錯誤的,因爲op表示自己錯了。 – Smuuf