2015-06-17 45 views
1
category: { 
    1: { 
     id: 1, 
     category_id: 7, 
     name: "N&E", 
     parent: 0, 
     created_at: "2015-06-17 01:36:03", 
     … 
    } 
    2: { 
     id: 2, 
     category_id: 8, 
     name: "Vauniya", 
     parent: 1, 
     created_at: "2015-06-17 01:36:03", 
     … 
    } 
    3: { 
     id: 3, 
     category_id: 9, 
     name: "MANNAR TOWN", 
     parent: 2, 
     created_at: "2015-06-17 01:36:03", 
     … 
    } 
    4: { 
     id: 4, 
     category_id: 10, 
     name: "KANDASAMY CHANDRAMURALI", 
     parent: 3, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
    5: { 
     id: 5, 
     category_id: 11, 
     name: "", 
     parent: 4, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
    6: { 
     id: 6, 
     category_id: 12, 
     name: "MATHUSHAN STORE", 
     parent: 5, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
    7: { 
     id: 7, 
     category_id: 13, 
     name: "E.H PREMACHANDRAN", 
     parent: 6, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
    8: { 
     id: 8, 
     category_id: 14, 
     name: "56870", 
     parent: 7, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
    9: { 
     id: 9, 
     category_id: 18, 
     name: "E & D", 
     parent: 7, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
    10: { 
     id: 10, 
     category_id: 19, 
     name: "PUNITHA PAVAN HOTEL", 
     parent: 9, 
     created_at: "2015-06-17 01:36:04", 
     … 
    } 
} 

使用此陣,我想獲得數組這樣我有數組對象,我想跟隨輸出在PHP

mapArray(
array(
array(
     'children' => array(
     array(
      'children' => array(
       array(
       'children' => array(
        array(
        'children' => array() 
       ), 
        array(
        'children' => array() 
       ) 
       ) 
      ), 
       array(
       'children' => array() 
      ) 
      ) 
     ), 
      array(
      'children' => array() 
     ) 
     ) 
    ), 
    array(
     'children' => array() 
    ), 
    array(
     'children' => array() 
    ) 
) 
); 
+0

你能告訴什麼是孩子的孩子之間的關係,按您的陣列 –

+0

這是關係。有像 區域(category_id = 0) - > area(category_id = 1) - >地域(category_id = 3) - > asm(category_id = 4)...-> outlet(category_id = 19)這 – Sriya

+0

存在一個ID 1:{ ID:1, CATEGORY_ID:7, 名: 「N&E」, 父:0 } 和這個ID可以是另一個的父 – Sriya

回答

1

Sriya,

那是你的意思?

Array 
(
    [1] => Array 
     (
      [category_id] => 7 
      [name] => A 
      [parent] => 0 
      [created_at] => 2015-06-17 01:36:03 
      [2] => Array 
       (
        [category_id] => 8 
        [name] => B 
        [parent] => 0 
        [created_at] => 2015-06-17 01:36:03 
        [3] => Array 
         (
          [category_id] => 9 
          [name] => C 
          [parent] => 0 
          [created_at] => 2015-06-17 01:36:03 
          [4] => Array 
           (
            [category_id] => 10 
            [name] => D 
            [parent] => 0 
            [created_at] => 2015-06-17 01:36:03 
            [5] => Array 
             (
              [category_id] => 11 
              [name] => E 
              [parent] => 0 
              [created_at] => 2015-06-17 01:36:03 
              [6] => Array 
               (
                [category_id] => 12 
                [name] => F 
                [parent] => 0 
                [created_at] => 2015-06-17 01:36:03 
                [7] => Array 
                 (
                  [category_id] => 13 
                  [name] => G 
                  [parent] => 0 
                  [created_at] => 2015-06-17 01:36:03 
                  [8] => Array 
                   (
                    [category_id] => 14 
                    [name] => H 
                    [parent] => 0 
                    [created_at] => 2015-06-17 01:36:03 
                   ) 

                 ) 

               ) 

             ) 

           ) 

         ) 

       ) 

     ) 

) 

我讓這個樣子,

> $category = array('1' => array('category_id' => '7', 
>           'name'   => 'A', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '2'=> array('category_id' => '8', 
>           'name'   => 'B', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '3'=> array('category_id' => '9', 
>           'name'   => 'C', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '4'=> array('category_id' => '10', 
>           'name'   => 'D', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '5'=> array('category_id' => '11', 
>           'name'   => 'E', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '6'=> array('category_id' => '12', 
>           'name'   => 'F', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '7'=> array('category_id' => '13', 
>           'name'   => 'G', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03', 
>           '8'=> array('category_id' => '14', 
>           'name'   => 'H', 
>           'parent'  => '0', 
>           'created_at' => '2015-06-17 01:36:03'))))))))); print_r($category); 
+0

燁看起來像這樣 – Sriya

相關問題