doulingzhuang3079 2012-03-29 01:44
浏览 55

循环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">';
}
  • 写回答

1条回答 默认 最新

  • duanfa2014 2012-04-21 18:47
    关注

    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'];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端