Home  >  Article  >  Backend Development  >  关于php数组的处理

关于php数组的处理

WBOY
WBOYOriginal
2016-06-23 13:18:25717browse

现有:
$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                )        ))

谢谢斑竹

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn