我有一个像这样的数组..
Array
(
[0] => Array
(
[0] => 1``
[1] => 2``
[2] => 3``
)
[1] => Array
(
[0] => 4``
[1] => 5``
[2] => 6``
)
[2] => Array
(
[0] =>
[1] => 7``
[2] =>
)
)
我想要下面的结果,
$remaining_value = Array
(
[0] => 1`` 4``,
[1] => 2`` 5`` 7``,
[2] => 3`` 6``,
)
如何在一个循环中执行此操作.. Plz帮助我..
答案 0 :(得分:1)
如果较低级别的数组总是具有相同数量的元素,那么您可以执行以下操作:
$subArrayCount = count( $inputArray );
$outputArray = array();
$firstSubArray = reset( $inputArray );
foreach( $firstSubArray as $key => $value )
{
$outputArray[$key] = $value;
for( $innerLoop = 1; $innerLoop < $subArrayCount; $innerLoop++ )
{
$outputArray[$key].= $inputArray[$innerLoop][$key];
}
}
var_dump( $outputArray );
答案 1 :(得分:0)
这应该有效:
<?php
$remaining_value=array();
foreach($array as $loopv1){
foreach($loopv1 as $key2 => $loopv2){
if(empty($remaining_value[$key2]))$remaining_value[$key2]=$loopv2; else $remaining_value[$key2].=" ".$loopv2;
}
}
?>