I have the following array that I want to return as a single level so I can output it to a CSV. I need to keep the array keys. The arrays that are "children_data" I want to move to the same level as the parent array.
array(8) {
["id"]=>
int(2)
["parent_id"]=>
int(1)
["name"]=>
string(16) "Category 1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(1)
["product_count"]=>
int(1)
["children_data"]=>
array(3) {
[0]=>
array(8) {
["id"]=>
int(2380)
["parent_id"]=>
int(2)
["name"]=>
string(11) "subcat 1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(2)
["product_count"]=>
int(1)
["children_data"]=>
array(4) {
[0]=>
array(8) {
["id"]=>
int(2381)
["parent_id"]=>
int(2380)
["name"]=>
string(11) "subsub cat 1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(3)
["product_count"]=>
int(1)
["children_data"]=>
array(7) {
[0]=>
array(8) {
["id"]=>
int(2382)
["parent_id"]=>
int(2381)
["name"]=>
string(21) "subsubsub cat1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(4)
["product_count"]=>
int(1)
["children_data"]=>
array(19) {
[0]=>
array(8) {
["id"]=>
int(2383)
["parent_id"]=>
int(2382)
["name"]=>
string(12) "subsubssubsubb cat1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(5)
["product_count"]=>
int(0)
["children_data"]=>
array(4) {
[0]=>
array(8) {
["id"]=>
int(2384)
["parent_id"]=>
int(2383)
["name"]=>
string(13) "subsub1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(6)
["product_count"]=>
int(0)
["children_data"]=>
array(0) {
}
}
[1]=>
array(8) {
["id"]=>
int(2385)
["parent_id"]=>
int(2383)
["name"]=>
string(10) "subsub2"
["is_active"]=>
bool(true)
["position"]=>
int(2)
["level"]=>
int(6)
["product_count"]=>
int(0)
["children_data"]=>
array(0) {
}
}
What I need is:
array(8) {
["id"]=>
int(2)
["parent_id"]=>
int(1)
["name"]=>
string(16) "Category 1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(1)
["product_count"]=>
int(1)
array(8) {
["id"]=>
int(2380)
["parent_id"]=>
int(2)
["name"]=>
string(11) "subcat 1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(2)
["product_count"]=>
int(1)
array(8) {
["id"]=>
int(2381)
["parent_id"]=>
int(2380)
["name"]=>
string(11) "subsub cat 1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(3)
["product_count"]=>
int(1)
array(8) {
["id"]=>
int(2382)
["parent_id"]=>
int(2381)
["name"]=>
string(21) "subsubsub cat1"
["is_active"]=>
bool(true)
["position"]=>
int(1)
["level"]=>
int(4)
["product_count"]=>
int(1)
ETC
I need this to create a comparison between our Main DB categories and Magento categories. This way when we do a product import via the API, I can match the Magento category with our Main DB category.