function finalByTreeLevel( $arrTree, $arrT ): array
{
$new_arr = [];
foreach($arrTree as $key => $item){
$item = array_reverse($item);
foreach($item as $key2 => $sub){
if ( !is_array( $sub )) {
if ( array_key_exists( $sub, $arrT )) {
$new_arr[$key] = [$sub => $arrT[$sub]];
} else {
$new_arr[$key] = [$sub => $new_arr[$key]];
}
}
}
}
return $new_arr;
}
array (size=80)
0 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
508 =>
array (size=1)
509 =>
array (size=1)
510 => null
1 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
508 =>
array (size=1)
515 =>
array (size=1)
516 => null
2 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
541 =>
array (size=1)
542 =>
array (size=1)
543 => null
array (size=1)
510 =>
array (size=5)
0 => string '509,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
516 =>
array (size=5)
0 => string '509,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
543 =>
array (size=5)
0 => string '509,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
array (size=80)
0 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
508 =>
array (size=1)
509 =>
array (size=1)
510 =>
array (size=5)
0 => string '509,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
1 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
508 =>
array (size=1)
515 =>
array (size=1)
516 =>
array (size=5)
0 => string '515,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
2 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
541 =>
array (size=1)
542 =>
array (size=1)
543 =>
array (size=5)
0 => string '542,541,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '100' (length=3)
4 => string 'мм' (length=4)
3 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
541 =>
array (size=1)
548 =>
array (size=1)
549 =>
array (size=5)
0 => string '548,541,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '100' (length=3)
4 => string 'мм' (length=4)
$new_arr = [];
foreach($arrTree as $key => $item){
$item = array_reverse($item);
foreach($item as $key2 => $sub){
if ( !is_array( $sub )) {
$new_arr[$key] = [$sub => $new_arr[$key]];
}
}
}
array (size=80)
0 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
508 =>
array (size=1)
509 =>
array (size=1)
510 => null
1 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
508 =>
array (size=1)
515 =>
array (size=1)
516 => null
2 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
541 =>
array (size=1)
542 =>
array (size=1)
543 => null
3 =>
array (size=1)
305 =>
array (size=1)
308 =>
array (size=1)
541 =>
array (size=1)
548 =>
array (size=1)
549 => null
array (size=80)
0 =>
array (size=1)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=1)
'val' => string '305' (length=3)
'val' => string '308' (length=3)
'val' => string '508' (length=3)
'val' => string '509' (length=3)
'val' => string '510' (length=3)
1 =>
array (size=1)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=1)
'val' => string '305' (length=3)
'val' => string '308' (length=3)
'val' => string '508' (length=3)
'val' => string '515' (length=3)
'val' => string '516' (length=3)
2 =>
array (size=1)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=1)
'val' => string '305' (length=3)
'val' => string '308' (length=3)
'val' => string '541' (length=3)
'val' => string '542' (length=3)
'val' => string '543' (length=3)
3 =>
array (size=1)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=1)
'val' => string '305' (length=3)
'val' => string '308' (length=3)
'val' => string '541' (length=3)
'val' => string '548' (length=3)
'val' => string '549' (length=3)
4 =>
array (size=1)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=2)
0 =>
array (size=1)
'val' => string '305' (length=3)
'val' => string '308' (length=3)
'val' => string '554' (length=3)
'val' => string '555' (length=3)
'val' => string '556' (length=3)
array (size=80)
0 =>
array (size=5)
0 => string '305' (length=3)
1 => string '308' (length=3)
2 => string '508' (length=3)
3 => string '509' (length=3)
4 =>
array (size=1)
510 =>
array (size=5)
0 => string '509,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
1 =>
array (size=5)
0 => string '305' (length=3)
1 => string '308' (length=3)
2 => string '508' (length=3)
3 => string '515' (length=3)
4 =>
array (size=1)
516 =>
array (size=5)
0 => string '515,508,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '150' (length=3)
4 => string 'мм' (length=4)
2 =>
array (size=5)
0 => string '305' (length=3)
1 => string '308' (length=3)
2 => string '541' (length=3)
3 => string '542' (length=3)
4 =>
array (size=1)
543 =>
array (size=5)
0 => string '542,541,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '100' (length=3)
4 => string 'мм' (length=4)
3 =>
array (size=5)
0 => string '305' (length=3)
1 => string '308' (length=3)
2 => string '541' (length=3)
3 => string '548' (length=3)
4 =>
array (size=1)
549 =>
array (size=5)
0 => string '548,541,308,305' (length=15)
1 => string '24767-2018' (length=10)
2 => string 'ширина' (length=12)
3 => string '100' (length=3)
4 => string 'мм' (length=4)
-- 305
|____308
|_____|___508
|_____|____|___509
|_____|____|____|___510
|_____|____|____|____|___0=> Ширина
|_____|____|____|____|___1=> мм
|_____|____|____|____|___2=> Высота
|_____|____|___515
|_____|____|____|___516
|_____|____|____|____|___0=> Ширина
|_____|____|____|____|___1=> мм
|_____|____|____|____|___2=> Высота
|_____|___554
|_____|____|___555
|_____|____|____|___556
|_____|____|____|____|___0=> Ширина
|_____|____|____|____|___1=> мм
|_____|____|____|____|___2=> Высота
-- 929
|____946
|_____|___949
|_____|____|___0=> Ширина
|_____|____|___1=> мм
|_____|____|___2=> Высота
-- 3118
|____3119
|_____|___3121
|_____|____|___0=> Ширина
|_____|____|___1=> мм
|_____|____|___2=> Высота
0 =>
array
0 => '305'
array
0 => '308'
array
0 => '508'
array
0 => '509'
array
0 => '510'
1 =>
array
0 => '305'
array
0 => '308'
array
0 => '508'
array
0 => '515'
array
0 => '516'
2 =>
array
0 => '305'
array
0 => '308'
array
0 => '508'
array
0 => '515'
array
0 => '516'
<div onload="loadData()" class="row" id="dataArray">
<!-- Загрузка данных через ajax -->
</div>
// Ожидание загрузки всей страницы
$(document).ready( function() {
loadData();
});
function loadData() {
$.ajax({
method: "POST",
url: "/mod/mod_news_load.php",
success: function( data ) {
if ( data != 'success' ) {
$("#dataArray").html( data );
}
}
});
}
<div onload="loadData()" class="row" id="dataArray">
<!-- Загрузка данных через ajax -->
</div>