关于php数组的处理
程序员文章站
2022-05-23 16:02:37
...
现有:
$arr = array(
Array('101-1148713','-68500','高岩'),
Array('101-1148713','-1464.6','高岩'),
Array('101-1148712','11','高岩'),
Array('101-1148713','98500','高岩'),
Array('101-1177035','-11068.4','全玮')
);
我怎么转化为
$arr = array(
'高岩'=>array(
'101-1148713'=>array('-68500','-1464.6','98500'),
'101-1148712'=>array('11');
),
'全玮'=>array(
'101-1177035'=>array('-11068.4')
)
);
$arr = array(
Array('101-1148713','-68500','高岩'),
Array('101-1148713','-1464.6','高岩'),
Array('101-1148712','11','高岩'),
Array('101-1148713','98500','高岩'),
Array('101-1177035','-11068.4','全玮')
);
我怎么转化为
$arr = array(
'高岩'=>array(
'101-1148713'=>array('-68500','-1464.6','98500'),
'101-1148712'=>array('11');
),
'全玮'=>array(
'101-1177035'=>array('-11068.4')
)
);
回复讨论(解决方案)
$arr = array( Array('101-1148713','-68500','高岩'), Array('101-1148713','-1464.6','高岩'), Array('101-1148712','11','高岩'), Array('101-1148713','98500','高岩'), Array('101-1177035','-11068.4','全玮'));foreach($arr as $v) { $res[$v[2]][$v[0]][] = $v[1];}print_r($res);
Array( [高岩] => Array ( [101-1148713] => Array ( [0] => -68500 [1] => -1464.6 [2] => 98500 ) [101-1148712] => Array ( [0] => 11 ) ) [全玮] => Array ( [101-1177035] => Array ( [0] => -11068.4 ) ))
谢谢斑竹
上一篇: 如何解剖一个网站?