Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 1st, 2012  |  syntax: None  |  size: 24.23 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function updateCategories($array) {
  2.                 $new_array = array ();
  3.                 $merge_array = array ();
  4.                 $tmp = array ();
  5.                 foreach ( $array as $key => $value ) {
  6.                         if (! is_array ( $value )) {
  7.                                 $tmp [0] [$key] = $value;
  8.                         } else {
  9.                                 $merge_array = $this->updateCategories ( $value );
  10.                         }
  11.                 }
  12.                 $new_array = array_merge ( $new_array, $tmp );
  13.                 return array_merge ( $new_array, $merge_array );
  14.         }
  15.  
  16. This is the result:
  17. Array
  18. (
  19.     [0] => Array
  20.         (
  21.             [category_id] => 1
  22.             [parent_id] => 0
  23.             [name] => Root Catalog
  24.             [is_active] =>
  25.             [position] => 7
  26.             [level] => 0
  27.         )
  28.  
  29.     [1] => Array
  30.         (
  31.             [category_id] => 2
  32.             [parent_id] => 1
  33.             [name] => Default Category
  34.             [is_active] => 1
  35.             [position] => 7
  36.             [level] => 1
  37.         )
  38.  
  39.     [2] => Array
  40.         (
  41.             [category_id] => 32
  42.             [parent_id] => 2
  43.             [name] => Linee Dati
  44.             [is_active] => 1
  45.             [position] => 15
  46.             [level] => 2
  47.         )
  48.  
  49.     [3] => Array
  50.         (
  51.             [category_id] => 23
  52.             [parent_id] => 32
  53.             [name] => Servizi Aggiuntivi
  54.             [is_active] => 1
  55.             [position] => 2
  56.             [level] => 3
  57.         )
  58.  
  59.     [4] => Array
  60.         (
  61.             [category_id] => 25
  62.             [parent_id] => 23
  63.             [name] => Shdsl Routers
  64.             [is_active] => 1
  65.             [position] => 3
  66.             [level] => 4
  67.         )
  68.  
  69. )
  70.  
  71.  
  72. Array
  73. (
  74.     [category_id] => 1
  75.     [parent_id] => 0
  76.     [name] => Root Catalog
  77.     [is_active] =>
  78.     [position] => 7
  79.     [level] => 0
  80.     [children] => Array
  81.         (
  82.             [0] => Array
  83.                 (
  84.                     [category_id] => 2
  85.                     [parent_id] => 1
  86.                     [name] => Default Category
  87.                     [is_active] => 1
  88.                     [position] => 7
  89.                     [level] => 1
  90.                     [children] => Array
  91.                         (
  92.                             [0] => Array
  93.                                 (
  94.                                     [category_id] => 3
  95.                                     [parent_id] => 2
  96.                                     [name] => Domini
  97.                                     [is_active] => 1
  98.                                     [position] => 7
  99.                                     [level] => 2
  100.                                     [children] => Array
  101.                                         (
  102.                                             [0] => Array
  103.                                                 (
  104.                                                     [category_id] => 28
  105.                                                     [parent_id] => 3
  106.                                                     [name] => Generici
  107.                                                     [is_active] => 1
  108.                                                     [position] => 2
  109.                                                     [level] => 3
  110.                                                     [children] => Array
  111.                                                         (
  112.                                                         )
  113.  
  114.                                                 )
  115.  
  116.                                             [1] => Array
  117.                                                 (
  118.                                                     [category_id] => 29
  119.                                                     [parent_id] => 3
  120.                                                     [name] => Geografici
  121.                                                     [is_active] => 1
  122.                                                     [position] => 3
  123.                                                     [level] => 3
  124.                                                     [children] => Array
  125.                                                         (
  126.                                                         )
  127.  
  128.                                                 )
  129.  
  130.                                             [2] => Array
  131.                                                 (
  132.                                                     [category_id] => 30
  133.                                                     [parent_id] => 3
  134.                                                     [name] => Commerciali
  135.                                                     [is_active] => 1
  136.                                                     [position] => 4
  137.                                                     [level] => 3
  138.                                                     [children] => Array
  139.                                                         (
  140.                                                         )
  141.  
  142.                                                 )
  143.  
  144.                                         )
  145.  
  146.                                 )
  147.  
  148.                             [1] => Array
  149.                                 (
  150.                                     [category_id] => 4
  151.                                     [parent_id] => 2
  152.                                     [name] => Hostings
  153.                                     [is_active] => 1
  154.                                     [position] => 9
  155.                                     [level] => 2
  156.                                     [children] => Array
  157.                                         (
  158.                                             [0] => Array
  159.                                                 (
  160.                                                     [category_id] => 6
  161.                                                     [parent_id] => 4
  162.                                                     [name] => Piani Hosting Generici
  163.                                                     [is_active] => 1
  164.                                                     [position] => 2
  165.                                                     [level] => 3
  166.                                                     [children] => Array
  167.                                                         (
  168.                                                         )
  169.  
  170.                                                 )
  171.  
  172.                                             [1] => Array
  173.                                                 (
  174.                                                     [category_id] => 19
  175.                                                     [parent_id] => 4
  176.                                                     [name] => Piani Hosting eCommerce
  177.                                                     [is_active] => 1
  178.                                                     [position] => 3
  179.                                                     [level] => 3
  180.                                                     [children] => Array
  181.                                                         (
  182.                                                         )
  183.  
  184.                                                 )
  185.  
  186.                                             [2] => Array
  187.                                                 (
  188.                                                     [category_id] => 5
  189.                                                     [parent_id] => 4
  190.                                                     [name] => Servizi Aggiuntivi
  191.                                                     [is_active] => 1
  192.                                                     [position] => 4
  193.                                                     [level] => 3
  194.                                                     [children] => Array
  195.                                                         (
  196.                                                         )
  197.  
  198.                                                 )
  199.  
  200.                                             [3] => Array
  201.                                                 (
  202.                                                     [category_id] => 21
  203.                                                     [parent_id] => 4
  204.                                                     [name] => Hosting per Rivenditori
  205.                                                     [is_active] => 1
  206.                                                     [position] => 7
  207.                                                     [level] => 3
  208.                                                     [children] => Array
  209.                                                         (
  210.                                                         )
  211.  
  212.                                                 )
  213.  
  214.                                             [4] => Array
  215.                                                 (
  216.                                                     [category_id] => 22
  217.                                                     [parent_id] => 4
  218.                                                     [name] => Hosting Evoluti
  219.                                                     [is_active] => 1
  220.                                                     [position] => 9
  221.                                                     [level] => 3
  222.                                                     [children] => Array
  223.                                                         (
  224.                                                         )
  225.  
  226.                                                 )
  227.  
  228.                                         )
  229.  
  230.                                 )
  231.  
  232.                             [2] => Array
  233.                                 (
  234.                                     [category_id] => 8
  235.                                     [parent_id] => 2
  236.                                     [name] => Software
  237.                                     [is_active] => 1
  238.                                     [position] => 10
  239.                                     [level] => 2
  240.                                     [children] => Array
  241.                                         (
  242.                                             [0] => Array
  243.                                                 (
  244.                                                     [category_id] => 9
  245.                                                     [parent_id] => 8
  246.                                                     [name] => eCommerce
  247.                                                     [is_active] => 1
  248.                                                     [position] => 2
  249.                                                     [level] => 3
  250.                                                     [children] => Array
  251.                                                         (
  252.                                                             [0] => Array
  253.                                                                 (
  254.                                                                     [category_id] => 17
  255.                                                                     [parent_id] => 9
  256.                                                                     [name] => Moduli di Pagamento
  257.                                                                     [is_active] => 1
  258.                                                                     [position] => 2
  259.                                                                     [level] => 4
  260.                                                                     [children] => Array
  261.                                                                         (
  262.                                                                         )
  263.  
  264.                                                                 )
  265.  
  266.                                                             [1] => Array
  267.                                                                 (
  268.                                                                     [category_id] => 18
  269.                                                                     [parent_id] => 9
  270.                                                                     [name] => Moduli Aggiuntivi Magento
  271.                                                                     [is_active] => 1
  272.                                                                     [position] => 4
  273.                                                                     [level] => 4
  274.                                                                     [children] => Array
  275.                                                                         (
  276.                                                                         )
  277.  
  278.                                                                 )
  279.  
  280.                                                         )
  281.  
  282.                                                 )
  283.  
  284.                                             [1] => Array
  285.                                                 (
  286.                                                     [category_id] => 10
  287.                                                     [parent_id] => 8
  288.                                                     [name] => Gestionali
  289.                                                     [is_active] => 1
  290.                                                     [position] => 4
  291.                                                     [level] => 3
  292.                                                     [children] => Array
  293.                                                         (
  294.                                                         )
  295.  
  296.                                                 )
  297.  
  298.                                             [2] => Array
  299.                                                 (
  300.                                                     [category_id] => 27
  301.                                                     [parent_id] => 8
  302.                                                     [name] => Web Sites
  303.                                                     [is_active] => 1
  304.                                                     [position] => 6
  305.                                                     [level] => 3
  306.                                                     [children] => Array
  307.                                                         (
  308.                                                         )
  309.  
  310.                                                 )
  311.  
  312.                                         )
  313.  
  314.                                 )
  315.  
  316.                             [3] => Array
  317.                                 (
  318.                                     [category_id] => 11
  319.                                     [parent_id] => 2
  320.                                     [name] => Servizi
  321.                                     [is_active] => 1
  322.                                     [position] => 11
  323.                                     [level] => 2
  324.                                     [children] => Array
  325.                                         (
  326.                                             [0] => Array
  327.                                                 (
  328.                                                     [category_id] => 26
  329.                                                     [parent_id] => 11
  330.                                                     [name] => Messaggistica Integrata
  331.                                                     [is_active] => 1
  332.                                                     [position] => 4
  333.                                                     [level] => 3
  334.                                                     [children] => Array
  335.                                                         (
  336.                                                         )
  337.  
  338.                                                 )
  339.  
  340.                                             [1] => Array
  341.                                                 (
  342.                                                     [category_id] => 14
  343.                                                     [parent_id] => 11
  344.                                                     [name] => eLearning
  345.                                                     [is_active] => 1
  346.                                                     [position] => 5
  347.                                                     [level] => 3
  348.                                                     [children] => Array
  349.                                                         (
  350.                                                         )
  351.  
  352.                                                 )
  353.  
  354.                                             [2] => Array
  355.                                                 (
  356.                                                     [category_id] => 12
  357.                                                     [parent_id] => 11
  358.                                                     [name] => Assistenza & Tutoring
  359.                                                     [is_active] => 1
  360.                                                     [position] => 6
  361.                                                     [level] => 3
  362.                                                     [children] => Array
  363.                                                         (
  364.                                                         )
  365.  
  366.                                                 )
  367.  
  368.                                         )
  369.  
  370.                                 )
  371.  
  372.                             [4] => Array
  373.                                 (
  374.                                     [category_id] => 16
  375.                                     [parent_id] => 2
  376.                                     [name] => Promozioni
  377.                                     [is_active] => 1
  378.                                     [position] => 14
  379.                                     [level] => 2
  380.                                     [children] => Array
  381.                                         (
  382.                                         )
  383.  
  384.                                 )
  385.  
  386.                             [5] => Array
  387.                                 (
  388.                                     [category_id] => 32
  389.                                     [parent_id] => 2
  390.                                     [name] => Linee Dati
  391.                                     [is_active] => 1
  392.                                     [position] => 15
  393.                                     [level] => 2
  394.                                     [children] => Array
  395.                                         (
  396.                                             [0] => Array
  397.                                                 (
  398.                                                     [category_id] => 33
  399.                                                     [parent_id] => 32
  400.                                                     [name] => ADSL
  401.                                                     [is_active] => 1
  402.                                                     [position] => 0
  403.                                                     [level] => 3
  404.                                                     [children] => Array
  405.                                                         (
  406.                                                             [0] => Array
  407.                                                                 (
  408.                                                                     [category_id] => 34
  409.                                                                     [parent_id] => 33
  410.                                                                     [name] => ADSL Standard
  411.                                                                     [is_active] => 1
  412.                                                                     [position] => 1
  413.                                                                     [level] => 4
  414.                                                                     [children] => Array
  415.                                                                         (
  416.                                                                         )
  417.  
  418.                                                                 )
  419.  
  420.                                                             [1] => Array
  421.                                                                 (
  422.                                                                     [category_id] => 35
  423.                                                                     [parent_id] => 33
  424.                                                                     [name] => ADSL Naked
  425.                                                                     [is_active] => 1
  426.                                                                     [position] => 2
  427.                                                                     [level] => 4
  428.                                                                     [children] => Array
  429.                                                                         (
  430.                                                                         )
  431.  
  432.                                                                 )
  433.  
  434.                                                         )
  435.  
  436.                                                 )
  437.  
  438.                                             [1] => Array
  439.                                                 (
  440.                                                     [category_id] => 13
  441.                                                     [parent_id] => 32
  442.                                                     [name] => SHDSL
  443.                                                     [is_active] => 1
  444.                                                     [position] => 1
  445.                                                     [level] => 3
  446.                                                     [children] => Array
  447.                                                         (
  448.                                                         )
  449.  
  450.                                                 )
  451.  
  452.                                             [2] => Array
  453.                                                 (
  454.                                                     [category_id] => 23
  455.                                                     [parent_id] => 32
  456.                                                     [name] => Servizi Aggiuntivi
  457.                                                     [is_active] => 1
  458.                                                     [position] => 2
  459.                                                     [level] => 3
  460.                                                     [children] => Array
  461.                                                         (
  462.                                                             [0] => Array
  463.                                                                 (
  464.                                                                     [category_id] => 24
  465.                                                                     [parent_id] => 23
  466.                                                                     [name] => Indirizzi IP Statici
  467.                                                                     [is_active] => 1
  468.                                                                     [position] => 2
  469.                                                                     [level] => 4
  470.                                                                     [children] => Array
  471.                                                                         (
  472.                                                                         )
  473.  
  474.                                                                 )
  475.  
  476.                                                             [1] => Array
  477.                                                                 (
  478.                                                                     [category_id] => 25
  479.                                                                     [parent_id] => 23
  480.                                                                     [name] => Shdsl Routers
  481.                                                                     [is_active] => 1
  482.                                                                     [position] => 3
  483.                                                                     [level] => 4
  484.                                                                     [children] => Array
  485.                                                                         (
  486.                                                                         )
  487.  
  488.                                                                 )
  489.  
  490.                                                         )
  491.  
  492.                                                 )
  493.  
  494.                                         )
  495.  
  496.                                 )
  497.  
  498.                         )
  499.  
  500.                 )
  501.  
  502.         )
  503.  
  504. )