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

关于php数组的处理

WBOY
Release: 2016-06-23 13:18:25
Original
763 people have browsed it

现有:
$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);
Copy after login
Array(    [高岩] => Array        (            [101-1148713] => Array                (                    [0] => -68500                    [1] => -1464.6                    [2] => 98500                )            [101-1148712] => Array                (                    [0] => 11                )        )    [全玮] => Array        (            [101-1177035] => Array                (                    [0] => -11068.4                )        ))
Copy after login

谢谢斑竹

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template