首頁 >後端開發 >php教程 >数组操作解决思路

数组操作解决思路

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-13 10:11:50798瀏覽

数组操作

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->array (  'time' => '2012-03-05 13',  'type' => 'ETC56-605N',  'count' => '52',)array (  'time' => '2012-03-05 14',  'type' => 'ETC56-605N',  'count' => '8',)array (  'time' => '2012-03-05 14',  'type' => 'ETC56-542N',  'count' => '39',)array (  'time' => '2012-03-05 15',  'type' => 'ETC56-542N',  'count' => '41',)array (  'time' => '2012-03-05 15',  'type' => 'ETC61-560N',  'count' => '10',)

如何变成array(time=>array(type=>count))这种形式?

------解决方案--------------------
这样?
PHP code
$arr = array(        array (          'time' => '2012-03-05 13',          'type' => 'ETC56-605N',          'count' => '52',        ),          array (          'time' => '2012-03-05 14',          'type' => 'ETC56-605N',          'count' => '8',        ),          array (          'time' => '2012-03-05 14',          'type' => 'ETC56-542N',          'count' => '39',        ),          array (          'time' => '2012-03-05 15',          'type' => 'ETC56-542N',          'count' => '41',        ),          array (          'time' => '2012-03-05 15',          'type' => 'ETC61-560N',          'count' => '10',        )   );foreach($arr as $array){        $newarr[$array['time']][$array['type']] += $array['count'];}print_r($newarr);<div class="clear">
                 
              
              
        
            </div>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn