我想在數據庫查詢後回顯日期列的結果,但是在嘗試回顯變量之前,如果我在$數組上調用var_dump,字符串將只回顯到屏幕。PHP 5.3從assoc數組中回顯一個日期對象?
如果我取消註釋「// var_dump($ assocArray [0] [」date「]);」那麼我可以迴應日期,否則什麼都不會迴應......這裏發生了什麼?
$link = sqlsrv_connect("localhost", array("UID" => 'myuser', "PWD" => 'mypass', "Database"=>'mydb'));
$result = sqlsrv_query($link, "select date from mytable where id=1");
$i=0;
while($row=sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC))
{
$assocArray[$i] = $row;
$i++;
}
sqlsrv_free_stmt($result);
sqlsrv_close($link);
echo "\n Dump AssocArray: \n";
echo "====================\n";
//var_dump($assocArray[0]["date"]);
echo "\n\n Echo Date: \n";
echo "====================\n";
echo $assocArray[0]["date"]->date; //doesnt print
echo "\n\n Dump Date: \n";
echo "====================\n";
var_dump($assocArray[0]["date"]);
/* result of Dump Date:
object(DateTime)#1 (3) {
["date"]=>
string(19) "2011-01-20 04:00:00"
["timezone_type"]=>
int(3)
["timezone"]=>
string(28) "America/Indiana/Indianapolis"
}
*/
看起來像一個格式的調用是必需的,var_dump的東西把我扔了....(echo $ assocArray [0] [「date」] - > format('Ymd H: I:S')) – ActionOwl 2011-01-20 20:18:38