数组排序 - php将数组键值相同的数组合并数组为一个数组

WBOY
풀어 주다: 2016-06-06 20:16:00
원래의
1122명이 탐색했습니다.

<code>Array (
    [question_id] => Array ( [0] => 4 [1] => 4 [2] => 4 [3] => 4 [4] => 4 [5] => 4 [6] => 4 [7] => 4 ) 
    [result_branch] => Array ( [0] => 126 [1] => 130[2] => 134 [3] => 1232 [4] => 128134 [5] => 16 [6] => 128134 [7] => 12136 
    [text] => Array ( [0] => 3213 [1] => qweq [2] => wdas [3] => d [4] => cxzc [5] => xzczx [6] => czx [7] => saed ) 
)
</code>
로그인 후 복사
로그인 후 복사

输出:

<code>Array (array([question_id]=>4,[result_branch]=>126,[text]=>3213 ),
    array([question_id]=>4,[result_branch]=>130,[text]=>qweq ),
    array([question_id]=>4,[result_branch]=>134 ,[text]=>wdas ),
    array([question_id]=>4,[result_branch]=>1232 ,[text]=>d ),
...
    array([question_id]=>4,[result_branch]=>12136 ,[text]=>saed ),

)</code>
로그인 후 복사
로그인 후 복사

回复内容:

<code>Array (
    [question_id] => Array ( [0] => 4 [1] => 4 [2] => 4 [3] => 4 [4] => 4 [5] => 4 [6] => 4 [7] => 4 ) 
    [result_branch] => Array ( [0] => 126 [1] => 130[2] => 134 [3] => 1232 [4] => 128134 [5] => 16 [6] => 128134 [7] => 12136 
    [text] => Array ( [0] => 3213 [1] => qweq [2] => wdas [3] => d [4] => cxzc [5] => xzczx [6] => czx [7] => saed ) 
)
</code>
로그인 후 복사
로그인 후 복사

输出:

<code>Array (array([question_id]=>4,[result_branch]=>126,[text]=>3213 ),
    array([question_id]=>4,[result_branch]=>130,[text]=>qweq ),
    array([question_id]=>4,[result_branch]=>134 ,[text]=>wdas ),
    array([question_id]=>4,[result_branch]=>1232 ,[text]=>d ),
...
    array([question_id]=>4,[result_branch]=>12136 ,[text]=>saed ),

)</code>
로그인 후 복사
로그인 후 복사

<code>
$arr = Array (
    'question_id' => Array ( 4, 4, 4, 4, 4),
    'result_branch' => Array (126, 130, 134 ,1232 ,128134),
    'text' => Array (3213,'qweq', 'wdas', 'd ','cxzc' )
);

$idNum = count($arr['question_id']);
$branchNum = count($arr['result_branch']);
$textNum = count($arr['text']);

$countMax = ($idNum > $branchNum ? $idNum : $branchNum) > $textNum ? ($idNum > $branchNum ? $idNum : $branchNum) : $textNum;

$result = array();
for($i=0; $i  isset($arr['question_id'][$i]) ? $arr['question_id'][$i] : '',
        'result_branch' =>  isset($arr['result_branch'][$i]) ? $arr['result_branch'][$i] : '',
        'text' =>  isset($arr['text'][$i]) ? $arr['text'][$i] : ''
    );
    $result[] = $temp;
}
echo "<pre class="brush:php;toolbar:false">";
print_r($result);
echo "
로그인 후 복사
";

数组排序 - php将数组键值相同的数组合并数组为一个数组
简单的写了一段,感觉不是很好。

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!