Witam,
Muszę wyrzucić z tablicy tablice, w której brakuje danych pomiędzy.
Przykładowe dane:
Array
(
[key1] => Array
(
[1] => Array
(
[0] =>
[1] => cos-LV0
[2] =>
[3] =>
[4] =>
[5] =>
)
[3] => Array
(
[0] =>
[1] => cos-LV1.5
[2] =>
[3] =>
[4] =>
[5] =>
)
[4] => Array
(
[0] =>
[1] => cos-LV2
[2] =>
[3] =>
[4] =>
[5] =>
)
[5] => Array
(
[0] =>
[1] => cos-LV4
[2] =>
[3] =>
[4] =>
[5] =>
)
[6] => Array
(
[0] =>
[1] => cos-LV5
[2] =>
[3] =>
[4] =>
[5] =>
)
[7] => Array
(
[0] =>
[1] => cos-Lv6
[2] =>
[3] =>
[4] =>
[5] =>
)
[8] => Array
(
[0] =>
[1] => cos-LV7
[2] =>
[3] =>
[4] =>
[5] =>
)
[9] => Array
(
[0] =>
[1] => cos-LV8
[2] =>
[3] =>
[4] =>
[5] =>
)
)
[key2] => Array
(
[1] => Array
(
[0] =>
[1] => ktos-LV0
[2] =>
[3] =>
[4] =>
[5] =>
)
[3] => Array
(
[0] =>
[1] => ktos-LV1.5
[2] =>
[3] =>
[4] =>
[5] =>
)
[4] => Array
(
[0] =>
[1] => ktos-LV2
[2] =>
[3] =>
[4] =>
[5] =>
)
[5] => Array
(
[0] =>
[1] => ktos-LV4
[2] =>
[3] =>
[4] =>
[5] =>
)
[6] => Array
(
[0] =>
[1] => ktos-LV5
[2] =>
[3] =>
[4] =>
[5] =>
)
[7] => Array
(
[0] =>
[1] => ktos-LV6
[2] =>
[3] =>
[4] =>
[5] =>
)
[8] => Array
(
[0] =>
[1] => ktos-LV7
[2] =>
[3] =>
[4] =>
[5] =>
)
[9] => Array
(
[0] =>
[1] => ktos-LV8
[2] =>
[3] =>
[4] =>
[5] =>
)
)
)
Mój kod, który niestety nie usuwa błędnych tablic(takich, które powinien)
protected function removeArrayIfThereIsMissingLevel($a){
$count = count($a);
$tab = [];
for($i=0; $i<$count-1; $i++){
if(isset($a[$i]) && isset($a[$i+1])){
$from1 = stripos($a[$i][1],'lv');
$from2 = stripos($a[$i+1][1],'lv');
$to1 = stripos($a[$i+1][1],'.');
$to2 = stripos($a[$i+1][1],'.');
if($from1!=false && $from2!=false){
$stringToCheck1 = substr($a[$i][1],$from1+2,$to1+1);
$stringToCheck2 = substr($a[$i+1][1],$from2+2,$to2+1);
if($stringToCheck1+1 == $stringToCheck2){
$tab[$a[$i][2]] = true;
} else {
return false;
}
}
}
}
return true;
}
Mógłbym prosić o pomoc?
Z góry dziękuje