我想从PHP
获得Json的结果[
[Date.UTC(2013,5,2),76.95],
[Date.UTC(2013,5,3),76.48],
[Date.UTC(2013,5,4),76.45],
[Date.UTC(2013,5,5),764.38],
[Date.UTC(2013,5,6),5.49],
[Date.UTC(2013,5,7),635.62],
[Date.UTC(2013,6,1),76.54],
[Date.UTC(2013,6,2),77.05],
[Date.UTC(2013,6,3),76.87]
]
我现在通过下面的代码得到了低于结果,尝试了很多东西但是无法使它工作。需要专家帮助...
while($selected = $statement->fetch()){
$value[] = date('Y,m,d', strtotime( $selected['start_date'] ) );
$value[] = $selected['total_earn_amount'];
}
$daily_final_earn = json_encode($value,JSON_NUMERIC_CHECK);
结果,我现在有
[
"2016,10,09",43.5968,
"2016,10,10",240.54155,
"2016,10,11",26.39,
"2016,10,12",49.34905,
"2016,10,13",226.46,
"2016,10,14",41.53405,
"2016,10,15",282.2825,
"2016,10,16",147.3975,
"2016,10,17",39.115,
"2016,10,18",104.35825
]
答案 0 :(得分:0)
while($selected = $statement->fetch()){
$value[] = [
//date('Y,m,d', strtotime( $selected['start_date'] ) ),
'Date.UTC(' . date('Y,m,d', strtotime( $selected['start_date'] ) ) . ')',
$selected['total_earn_amount'],
];
}
$daily_final_earn = json_encode($value,JSON_NUMERIC_CHECK);
更新以获得相当于Date.UTC()
:
while($selected = $statement->fetch()){
$value[] = [
// `strtotime` returns number of seconds since epoch starts
// to get milliseconds - multiply it by 1000.
// same result will be received when using `Date.UTC()`
1000 * strtotime( $selected['start_date'] ),
$selected['total_earn_amount'],
];
}
$daily_final_earn = json_encode($value,JSON_NUMERIC_CHECK);