Created
September 26, 2012 13:45
-
-
Save petrabarus/3788134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arrs = Array( | |
12 => array( | |
'model' => 'aksesoris', | |
'children' => array( | |
1716 => array( | |
'model' => 'jam_tangan', | |
), | |
1717 => array( | |
'model' => 'kacamata_lainnya', | |
), | |
1718 => array( | |
'model' => 'perhiasan', | |
'children' => array( | |
'1715' => array( | |
'model' => 'testing', | |
) | |
) | |
), | |
1719 => array( | |
'model' => 'tas', | |
), | |
), | |
), | |
13 => array | |
( | |
'model' => 'batik_kebaya', | |
'children' => array( | |
1720 => array( | |
'model' => 'batik', | |
), | |
1721 => array | |
( | |
'model' => 'kebaya', | |
), | |
), | |
), | |
1706 => array( | |
'model' => 'busana_anak', | |
'children' => array( | |
1722 => array( | |
'model' => 'anak', | |
), | |
1723 => array( | |
'model' => 'bayi', | |
'children' => array( | |
9999 => array( | |
'model' => 'test', | |
), | |
8888 => array | |
( | |
'model' => 'test2', | |
), | |
), | |
), | |
), | |
), | |
1707 => array | |
( | |
'model' => 'busana_formil', | |
'children' => array | |
( | |
1724 => array | |
( | |
'model' => 'kerja', | |
), | |
1725 => array | |
( | |
'model' => 'sekolah', | |
), | |
), | |
), | |
1708 => array | |
( | |
'model' => 'busana_modis', | |
'children' => array | |
( | |
1726 => array | |
( | |
'model' => 'busana_import', | |
), | |
1727 => array | |
( | |
'model' => 'busana_lokal', | |
), | |
1728 => array | |
( | |
'model' => 'busana_spesial', | |
), | |
), | |
), | |
1709 => array | |
( | |
'model' => 'busana_muslim', | |
'children' => array | |
( | |
1729 => array | |
( | |
'model' => 'aksesoris_muslim', | |
), | |
1730 => array | |
( | |
'model' => 'Pakaian', | |
), | |
), | |
), | |
1710 => array | |
( | |
'model' => 'busana_tidur', | |
'children' => array | |
( | |
1731 => array | |
( | |
'model' => 'lingerie', | |
), | |
1732 => array | |
( | |
'model' => 'pakaian_tidur', | |
), | |
1733 => array | |
( | |
'model' => 'perlengkapan_tidur', | |
), | |
), | |
), | |
1711 => array | |
( | |
'model' => 'department_store', | |
'children' => array | |
( | |
1734 => array | |
( | |
'model' => 'menengah_ke_atas', | |
), | |
1735 => array | |
( | |
'model' => 'menengah_ke_bawah', | |
), | |
), | |
), | |
1712 => array | |
( | |
'model' => 'kaos', | |
'children' => array | |
( | |
1736 => array | |
( | |
'model' => 'konveksi', | |
), | |
1737 => array | |
( | |
'model' => 'retail', | |
), | |
), | |
), | |
1713 => array | |
( | |
'model' => 'rental_tailor', | |
'children' => array | |
( | |
1738 => array | |
( | |
'model' => 'busana_adat_pesta', | |
), | |
1739 => array | |
( | |
'model' => 'busana_lainnya', | |
), | |
1740 => array | |
( | |
'model' => 'tailor', | |
), | |
), | |
), | |
1714 => array | |
( | |
'model' => 'sepatu', | |
'children' => array | |
( | |
1741 => array | |
( | |
'model' => 'formal', | |
), | |
1742 => array | |
( | |
'model' => 'santai', | |
), | |
), | |
), | |
1715 => array | |
( | |
'model' => 'toko_grosir', | |
'children' => array | |
( | |
1743 => array | |
( | |
'model' => 'aksesoris_grosir', | |
), | |
1744 => array | |
( | |
'model' => 'pakaian_grosir', | |
), | |
1745 => array | |
( | |
'model' => 'sepatu_grosir', | |
), | |
), | |
), | |
); | |
$flatarr = array(); | |
function flattenarray($arrs, $parent = NULL) { | |
$flat = array(); | |
foreach($arrs as $idx => $arr){ | |
$flat[] = array( | |
'id' => $idx, | |
'model' => $arr['model'], | |
'parent' => $parent, | |
); | |
if (isset($arr['children'])){ | |
$flat = array_merge($flat, flattenarray($arr['children'], $idx)); | |
} | |
} | |
return $flat; | |
} | |
$flatarr = flattenarray($arrs); | |
print_r($flatarr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment