数据的格式话有关问题

WBOY
Release: 2016-06-13 11:15:44
Original
785 people have browsed it

求教:数据的格式话问题
数据源格式:

<br />$data = array(<br />  array('id' => 1,'pid' => 0,'name' => 'a'),<br />  array('id' => 2,'pid' => 0,'name' => 'b'),<br />  array('id' => 3,'pid' => 1,'name' => 'c'),<br />  array('id' => 4,'pid' => 1,'name' => 'd'),<br />  array('id' => 5,'pid' => 3,'name' => 'e'),<br />  array('id' => 6,'pid' => 3,'name' => 'f'),<br />  array('id' => 7,'pid' => 6,'name' => 'g'),<br />  array('id' => 8,'pid' => 6,'name' => 'h'),<br />  array('id' => 9,'pid' => 8,'name' => 'i'),<br />  array('id' => 10,'pid' => 8,'name' => 'j'),<br />  array('id' => 11,'pid' => 9,'name' => 'l'),<br />  array('id' => 12,'pid' => 9,'name' => 'm'),<br />);<br />
Copy after login

需要将数据格式话成如下格式:

Array(
  'a' => Array(
    'c' => 'c',
    'd' => Array(
      'e' => 'e',
      'f' => Array(
        'g' => 'g'
        'h' => Array(
          'i' => Array(
            'l' => 'l',
            'm' => 'm'
          ),
          'j' => 'j'
        ),
      )
    )
  ),
  'b' => 'b'
)
求各位大神帮忙


------解决方案--------------------
<?php <br />$data = array(<br>  array('id' => 1,'pid' => 0,'name' => 'a'),<br>  array('id' => 2,'pid' => 0,'name' => 'b'),<br>  array('id' => 3,'pid' => 1,'name' => 'c'),<br>  array('id' => 4,'pid' => 1,'name' => 'd'),<br>  array('id' => 5,'pid' => 3,'name' => 'e'),<br>  array('id' => 6,'pid' => 3,'name' => 'f'),<br>  array('id' => 7,'pid' => 6,'name' => 'g'),<br>  array('id' => 8,'pid' => 6,'name' => 'h'),<br>  array('id' => 9,'pid' => 8,'name' => 'i'),<br>  array('id' => 10,'pid' => 8,'name' => 'j'),<br>  array('id' => 11,'pid' => 9,'name' => 'l'),<br>  array('id' => 12,'pid' => 9,'name' => 'm'),<br>);<br>/********我是YD的分割线*************/<br>$pid = 1000000;<br>//$mark = 'c';<br>foreach ($data as $key => $value){<br>	<br>	if ($value[pid] == $pid) {<div class="clear">
                 
              
              
        
            </div>
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