$new_arr = array();
$arr = array(
'0' =>
array (
0 => '305',
1 => '308',
2 => '508',
3 => '509',
4 => '510',
),
'1' =>
array (
0 => '305',
1 => '308',
2 => '508',
3 => '515',
4 => '516',
),
'2' =>
array (
0 => '305',
1 => '308',
2 => '541',
3 => '542',
4 => '543',
),
'3' =>
array (
0 => '305',
1 => '308',
2 => '541',
3 => '548',
4 => '549',
),
'4' =>
array (
0 => '305',
1 => '308',
2 => '554',
3 => '555',
4 => '556',
),
'5' =>
array (
0 => '305',
1 => '308',
2 => '554',
3 => '561',
4 => '562',
),
);
foreach($arr as $key => $item){
$item = array_reverse($item);
foreach($item as $key2 => $sub){
$new_arr[$key]['val']= $sub;
$new_arr[$key] = ['0' => $new_arr[$key]];
}
}