我試圖訪問$ class-> diff_time('2014-02-11',date(「Ymd」))[0] ['date']的值,但它似乎它不可能轉換數組中的對象。甚至這種形式的函數()[table]是顯示數據的合法方法嗎?看起來很不自然。從數組對象獲取值(DateTime)
function diff_time($lowest,$highest){
/* input format @$lowest @$highest
Y-m-d
*/
$container = array();
$dStart = new DateTime($lowest);
$dEnd = new DateTime($highest);
$dDiff = $dStart->diff($dEnd);
$containser = array($dStart,$dEnd,$dDiff->days,$dDiff->format('%R'));
return $containser;
}
var_dump($class->diff_time('2014-02-11',date("Y-m-d")));
array(4) {
[0]=>
object(DateTime)#3 (3) {
["date"]=>
string(19) "2014-02-11 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
[1]=>
object(DateTime)#4 (3) {
["date"]=>
string(19) "2014-11-05 00:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
[2]=>
int(267)
[3]=>
string(1) "+"
}
print_r($class->diff_time('2014-02-11',date("Y-m-d"))[0]);
DateTime Object
(
[date] => 2014-02-11 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
什麼樣的價值是你想獲得? – 2014-11-05 20:53:43
@JohnConde [0] [「date」]和[1] [「date]因爲[2]和[3]很容易得到:) – Kavvson 2014-11-05 20:54:22
我還不知道你想要什麼價值 – 2014-11-05 20:54:49