重置数组中的键数


reset key count in array

我有一个这样的数组:

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等等。

不太确定我的解释是否正确,或者如何完成它。任何指导都是感激的。提前感谢!

对于拒绝索引,我建议您使用这些索引的数组。然后从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++:
}

我的解决方案是使用array_slice删除不需要的项,然后使用array_chuck删除剩余的项,最后在断点处丢弃剩余的项。