将字符串添加到数组中的每个日期
问题描述:
This is a simple questions. I do not know i'm not able to achieve this. How to add a string(Date.UTC) to each date in the row using php like show below
[Date.UTC(2011,11,20),5],[Date.UTC(2011,11,21),5]
As of now i have my result like this, just need to add Date.UTC string to each date in the row.
[["2011,09,03","1"],["2011,09,06","53"]]
这是一个简单的问题。 我不知道我无法做到这一点。 如何使用php添加字符串(Date.UTC)到行中的每个日期,如下面的显示 p>
[Date.UTC(2011,11,20),5], [Date.UTC(2011,11,21),5]
code> pre>
截至目前,我有这样的结果,只需要添加Date.UTC字符串即可 行中的每个日期。 p>
[[“2011,09,03”,“1”],[“2011,09,06”,“53”]] \ n code> pre>
div>
答
The data you have seems to be a valid json string so...
$json = '[["2011,09,03","1"],["2011,09,06","53"]]' ;
$dates = json_decode($json, true);
var_dump($dates);
foreach($dates as &$date){
$date[0] = "Date.UTC({$date[0]})" ;
}
var_dump($dates);
//Pack back to json if you need $json = json_encode($dates);