您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/3/2 21:14:04发布31次查看
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 ) )

输出:
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 ),)

回复内容: 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 ) )

输出:
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 ),)

$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 ;print_r($result);echo
;
简单的写了一段,感觉不是很好。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product