Home > Backend Development > PHP Tutorial > 数组操作解决思路

数组操作解决思路

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 13:38:42
Original
843 people have browsed it

数组操作

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',
)
Copy after login

如何变成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>
Copy after login
Related labels:
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
Latest Issues
How to create an array within an array?
From 1970-01-01 08:00:00
0
0
0
php array
From 1970-01-01 08:00:00
0
0
0
Array to array
From 1970-01-01 08:00:00
0
0
0
php array rotation
From 1970-01-01 08:00:00
0
0
0
array
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template