Array (
[0] => Array ( [class_id] => 160101 [stu_id] => 201611031501 [cou_id] => 1001 [res_id] => 60 )
[1] => Array ( [class_id] => 160101 [stu_id] => 201611031501 [cou_id] => 1002 [res_id] => 61 )
[2] => Array ( [class_id] => 160101 [stu_id] => 201611031501 [cou_id] => 1003 [res_id] => 62 )
[0] => Array ( [class_id] => 160101 [stu_id] => 201611031502 [cou_id] => 1001 [res_id] => 60 )
[1] => Array ( [class_id] => 160101 [stu_id] => 201611031502 [cou_id] => 1002 [res_id] => 61 )
[2] => Array ( [class_id] => 160101 [stu_id] => 201611031502 [cou_id] => 1003 [res_id] => 62 )
)
想要得到的是像这样的 Array ( [class_id] => 160101 [stu_id] => 201611031501 [1001] => 60 [1002] => 61 [1003] => 62 )
Array ( [class_id] => 160101 [stu_id] => 201611031502 [1001] => 60 [1002] => 61 [1003] => 62 )
你看一下补充,不是这样的
本回答被网友采纳php合并两个二维数组,如果两个二维数组的id值相等,则合并为一个新的数 ...
function mergeById(&$a,&$b){ c=array();foreach($a as $e)$c[$e['id']]=$e;foreach($b as $e)$c[$e['id']]=isset($c[$e['id']])? $c[$e['id']]+$e : $e;return $c;} a=\/\/数组一;b=\/\/数组二;var_dump(mergeById($b,$a));=== array 1 => array ...
php 如何取二维数组中某个值,并组合成另一个一维数组进行implode
<?php$array=array('0'=>array('name'=>'aaa','id'=>'22222'),'1'=>array('name'=>'bbb','id'=>'333'));$new = array();foreach ($array as $v){ $new[]=$v['id'];}$num = join(',',$new);echo $num;?> ...
php将二维数组值数组里某一个键值一样的拼装成一个三维数组
<?php $indexArr = array(); $newArr = array(); foreach ($sourceArr as $v) { \/\/ 判断该order_id是否已经存在于新数组中 if (array_key_exists($v['order_id'], $indexArr)) { \/\/ 获取该order_id在新数组中的位置 $k = $indexArr[$v['order_id']];...
PHP foreach把二维数组遍历成为一维数组(就是怎么样降维)???_百度知 ...
如果忽略重复和反向还原,那么直接用array_merge即可 new_arr = array_merge($arr['1'],$arr[2]);foreach:foreach($arr as $v=>$k){ foreach($v as $val=>$key){ $new_arr[$key] = $val; }}
php 怎样把一个二维数组合并一个数组
一个数组中的值附加在前一个数组的后面。返回作为结果的数组。如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。如果只给了一个数组并且该数组是数字索引的,则键名会以连续方式重新索引。
PHP二维数组转一维数组
其实这是一个数组转置算法,是很常用的算法,例子程序代码如下:<?php arr=array('oneid' => array ('4','5'),'id' => array ('4','5'),'Rname' => array ('商人' ,'VIP' ),'R0' => array ('30000' ,'100001' ),'R1' => array ('100000' ,'5000000' ),'chkall' =...
请教php二维数组转换为一维数组的问题
\/><?php$aa=Array ( '0'=> Array ('a' => 'VHeLF' ),'1' => Array ( 'b' => 'wS8WP'),'2'=> Array ( 'c' => '6HmW' )); foreach($aa as $u=>$v){ foreach($v as $uu=>$vv){ $bb[$uu]=$vv; }}print_r($bb);?> ...
PHP将二维数组中某个值都取出来组成一个新的数组
\/\/方法一$a="1-3,1-2,2-1";$arr1 = explode(',', $a);foreach ($arr1 as $v){ $tmp = explode('-', $v); $arr2[] = $tmp[0];}print_r($arr2);\/\/方法二preg_match_all("\/\\d+(?=-)\/", $a, $matches);print_r($matches);...
php 中如何给二维数组赋值
PHP给二位数组赋值的方式是非常灵活的,这里介绍三种方法(设二位数组$arr = array(array(1,2,3),array(4,5,6));):在已知二维数组元素个数的情况下,可以直接根据下标来赋值:arr[2] = array(7,8,9);\/\/ 给二维数组的第一维赋值。$arr[3][0] = 10;\/\/ 给二维数组的第二维元素赋值...
PHP合并具有相同键值的二维数组
arr=array(0=>array('a'=>'语言'),1=>array('b'=>'数学'),2=>array('a'=>'语文'));newarr=array();foreach($arr as $k=>$v){ foreach($v as $t=>$z){ newarr[$t][]=$z;} }