0

我有一个这样的数组:

Array{
    10 - 2011 Headlight Assembly Nissan Versa 
    11 - LH 07-11 INS QTLY O.E.M - FREE SAME DAY SHIPPING 
    12 - 000 
    13 - A0 
    14 - 40626A1 
    15 - $165 actual 
    16 - More Desc Stuff
}

这是从一个简单的 dom 结果产生的。列表中有多个项目。我想做的是在达到 17 后将键重置回 10,这样我就可以遍历数组中的所有结果并找到正确的值,而无需查找键 10、14、15 - 然后是键20、24、25 等

不太确定我是否正确解释了它,或者如何完成它。任何指导表示赞赏。提前致谢!

4

2 回答 2

0

我的解决方案是使用 array_slice 删除不必要的项目,然后使用 array_chuck 其余的,最后在断点处删除其余的。

于 2014-08-18T03:06:56.550 回答
0

好吧,对于要拒绝的索引,我建议您使用这些索引的数组。并从 10 到 16 循环遍历这个数组,然后回到 10,我建议你这样做

$indexes_to_deny = [14,15,16];
$index = 10;
while( condition to stop the loop )
{

    if($index%17===0)
      $index = 10;
    if(in_array($index,$indexes_to_deny))
    {
      $index++;
      continue; 
    }

    /*
        your code here 
        you can access the items inside the array with $array[$index]
    */ 

    $index++:
}
于 2014-08-18T01:21:24.470 回答