循环JSON文档,将字符串加载到数组中,然后操作该文档 [英] Looping JSON document, loading string into array then manipulating the document
问题描述
我正在遍历json响应,并希望将文档的一部分加载到数组中。
当前我只能回显已解析的字符串。
I am looping through a json response and want to load parts of the document into an array. Currently I'm only able to echo out the parsed strings.
foreach($data['movies'] as $item) {
echo $item['release_dates']['theater'];
}
我将如何更改它,以便将结果加载到数组中?
How would I go about changing this so it loads the result into an array?
我要放入数组中的解析字符串是日期
The parsed strings I want to put into the array are dates
此外,我有一个示例脚本可以查找两个日期之间的差异,并为差异循环图像。我可以操纵它,而不是找到变量之间的差异,而是找到在上一个数组循环中构造的数组对象之间的差异吗?
Furthermore I have an example script working that finds the difference between 2 dates and loops an image for the difference. Could I manipulate this so instead of finding the difference between the variables, it finds the difference between the array objects constructed in the previous array loop?
$d1 = strtotime('2012-04-04');
$d2 = strtotime('2012-03-31');
$interval=($d1-$d2)/(3600*24);
for ($i = 0; $i <= $interval; $i++)
{
echo '<img src="test.jpg">';
}
推荐答案
如果我理解这第一部分正确,那么这可能就是您要的?
If I understand this first part correctly, then this might be what you're asking for?
$dataArray = array();
foreach($data['movies'] as $item) {
$dataArray[] = $item['release_dates'];
}
这篇关于循环JSON文档,将字符串加载到数组中,然后操作该文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!