这里(如下所示)是我正在做的一些非常简单的 php 解析多维数组的东西。我只是在搜索“突出显示”键,然后将一些键值对存储在另一个数组中。有没有更好的方法来实现这一点(我的意思是关于性能),而不是有 n 个 foreach 循环来达到你想要的。
$json_O=json_decode(file_get_contents($url),true);
foreach($json_O as $section1=>$items1){
if($section1==highlighting){
foreach($items1 as $section2=>$items2){
$key=$section2;
foreach($items2 as $section3=>$items3){
foreach ($items3 as $section4=>$items4){
$value=$items4;
$found[]=array('Key' => $key, 'Value' => $value);
这是我要解析的示例 php 对象:
Array
(
[responseHeader] => Array
(
[status] => 0
[QTime] => 3
[params] => Array
(
[indent] => on
[start] => 0
[q] => russian
[fragsize] => 40
[hl.fl] => Data
[wt] => json
[hl] => on
[rows] => 8
)
)
[response] => Array
(
[numFound] => 71199
[start] => 0
[docs] => Array
......
......
[highlighting] => Array
(
[114360] => Array
(
[Data] => Array
(
[0] => AMEki has done it better <em>russian</em>...
....
....
现在有两件事:1)我可以做得更快吗?2)我可以设计得更好吗?