有效地循环遍历多维数组并在重复值上输出不同的内容

时间:2017-03-17 16:31:42

标签: php arrays performance

如何循环遍历多维数组以及与其他子数组具有相同值的子数组,在那里回显所有这些数组。这应该在每次遍历整个数组时不进行循环。我正在寻找比平方更好的东西。

$bigArray = [
  ["value" => $someValue, "importantValue" => $importantValue, "value_1" => $someValue],
  ["value" => $someValue, "importantValue" => $importantValue, "value_1" => $someValue],
  ["value" => $someValue, "importantValue" => $importantValue, "value_1" => $someValue]    
]

foreach($bigArray as $item){
  if($item[importantValue] has duplicates that can be all the way at the end of the parent array){
    echo "these are duplicates:". all the duplicates of that value here
    echo "duplicate 1: ".$item["value"].$item["importantValue"]
  } else {
    echo $item["value"].$item["importantValue"]
  }
}

0 个答案:

没有答案