我在php上执行此操作,无法组合正确的数组
array (
0 => 'uttt',
)
必须添加到数组
0 => '534',
1 => 'DT 8060',
2 => '6y45y',
**4 => 'uttt',**
并且所有数组也必须这样做 我不知道会排多少 这在foreach中做 请人帮帮我
array (
0 => 'uttt',
)
array (
0 => '534',
1 => 'DT 8060',
2 => '6y45y',
)
array (
0 => '639',
1 => 'DP 42',
2 => '88765',
)
array (
0 => '1470',
1 => '95126F',
2 => 'yt44y5',
)
array (
0 => '1473',
1 => '95406F',
2 => 'yyynb rt',
)
array (
0 => 'ytree',
)
array (
0 => '3338',
1 => 'DI 113 ШК',
2 => 'rdde',
)
array (
0 => '1476',
1 => '96010',
2 => 'ouuhh',
)
array (
0 => 'nnggg',
)
array (
0 => '2169',
1 => 'DT 88263-2',
2 => 'rhrd',
)
array (
0 => '2657',
1 => 'DP 10-1',
2 => 'klii',
)
array (
0 => 'ergerg',
)
array (
0 => '544',
1 => '96205',
2 => 'njnj sgsg',
)
我需要得到这样的阵列
array (
0 => '534',
1 => 'DT 8060',
2 => '6y45y',
3 => 'uttt',
)
array (
0 => '639',
1 => 'DP 42',
2 => '88765',
3 => 'uttt',
)
array (
0 => '1470',
1 => '95126F',
2 => 'yt44y5',
3 => 'uttt',
)
array (
0 => '1473',
1 => '95406F',
2 => 'yyynb rt',
3 => 'uttt',
)
array (
0 => '3338',
1 => 'DI 113 ШК',
2 => 'rdde',
3 => 'ytree',
)
array (
0 => '1476',
1 => '96010',
2 => 'ouuhh',
3 => 'ytree',
)
array (
0 => '2169',
1 => 'DT 88263-2',
2 => 'rhrd',
3 => 'nnggg',
)
array (
0 => '2657',
1 => 'DP 10-1',
2 => 'klii',
3 => 'nnggg',
)
array (
0 => '544',
1 => '96205',
2 => 'njnj sgsg',
0 => 'ergerg',
)
这是怎么回事?我不知道
答案 0 :(得分:0)
试试这个,
$finalArr = [];
foreach($currentArra as $arr):
if(count($arr) == 1){
$arrToBeMerge=[];
$arrToBeMerge = $arr;
}
if(!empty($arrToBeMerge) && count($arr)>1){
$result = array_merge($arr , $arrToBeMerge);
array_push($finalArr, $result);
}
endforeach;
echo '<pre>';print_r($finalArr);