Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何处理多维数组的数组_Php_Arrays_Multidimensional Array_Rss_Feedly - Fatal编程技术网

Php 如何处理多维数组的数组

Php 如何处理多维数组的数组,php,arrays,multidimensional-array,rss,feedly,Php,Arrays,Multidimensional Array,Rss,Feedly,下面的数组包含数组和数组。这只是一个条目;想象一下,现在我有20个源,每个源至少包含10个条目,如下所示。这是我想解决的噩梦 有谁能给我一些建议,告诉我如何在PHP中高效地解析这些内容,并能够获取每个值,以便能够将它们插入到数据库中进行进一步处理!!多谢各位 Array ( [id] => id [direction] => ltr [updated] => 1407220315278 [title] => Syria | The

下面的数组包含数组和数组。这只是一个条目;想象一下,现在我有20个源,每个源至少包含10个条目,如下所示。这是我想解决的噩梦

有谁能给我一些建议,告诉我如何在PHP中高效地解析这些内容,并能够获取每个值,以便能够将它们插入到数据库中进行进一步处理!!多谢各位

Array ( 
    [id] => id 
    [direction] => ltr 
    [updated] => 1407220315278 
    [title] => Syria | The Guardian 
    [alternate] => Array ( [0] => Array ( 
                                [href] => href 
                                [type] => text/html ) ) 
    [continuation] => 147a4ddf48e:28d98:bda086f 
    [items] => Array ( [0] => Array ( 
                                [keywords] => Array ( 
                                                [0] => Global development 
                                                [1] => Refugees 
                                                [2] => Syria 
                                                [3] => Middle East and North Africa 
                                                [4] => World news 
                                                [5] => UK news 
                                                [6] => Scotland 
                                                [7] => Conflict and development 
                                                [8] => Immigration and asylum ) 
                                [fingerprint] => 47075b4f 
                                [originId] => originId 
                                [id] => Te6w3H2VbpKKFda+uYdqytnutphL/kktv0RL7gq9jjU=_147a4ddf48e:28d98:bda086f 
                                [title] => A Syrian refugee in Scotland: 'I'm one of the lucky ones' video 
                                [published] => 1407218400000 
                                [crawled] => 1407220315278 
                                [alternate] => Array ( 
                                                [0] => Array ( 
                                                        [href] => href
                                                        [type] => text/html ) ) 
                                [author] => Produced by Claudine Spera and Ellie Violet Bramley 
                                [origin] => Array ( 
                                                [streamId] => streamId 
                                                [title] => Syria | The Guardian 
                                                [htmlUrl] => htmlUrl ) 
                                                [summary] => Array ( 
                                                                [direction] => ltr 
                                                                [content] => Ayman is one of about 3 million Syrian refugees living outside his homeland. After nine of his friends were killed in Damascus, Ayman used his student visa to flee to the UK, leaving his wife and twin boys behind. 'We didn't expect civil war in Syria, never, ever,' he says. But now, with the help of the Red Cross, the family are reunited and building a life in Edinburgh Continue reading... ) 
                                                [visual] => Array ( 
                                                                [url] => imagUrl
                                                                [height] => 252 
                                                                [width] => 600 
                                                                [contentType] => image/jpeg ) 
                                                [unread] => 1 
                                                [categories] => Array ( 
                                                                    [0] => Array ( 
                                                                                [id] => user/5312f2fe-1adc-476f-93da-8b1db5a63180/category/عربي 
                                                                                [label] => عربي ) ) 
                                                [engagement] => 4 [engagementRate] => 0.33 ) ) )

如果数组中始终存在相同的键,则使用如下内容进行迭代应该相对容易:

foreach($yourarray as $key1=>$item1){
  //dosomething
  if($key1=="alternate"){
     foreach($item1 as $key2=>$item2){
        //and so on
     }
  }

}

至于将其保存到数据库中,我承认这并不容易,而且我对数据库没有太多的经验,但如果我是你,我会将它们保存在多个表中,并带有1到n个引用。

首先,我想感谢你的建议:我尝试过,效果不错,但随着我的进步,我最终得到了3个或更多的foreach。我最后还不得不检查键和值,因为我肯定不想存储所有东西,比如URL、标题、PulblishedDate、图像URL,也许还有摘要。然而,在循环中搜索这些值有点累人,你不觉得吗?!