I need to push a second array into the first array by matching "cat_id" in the first array to "parent_id" in the second array.
I have the first array - $categories:
[
{
"cat_id": "350",
"parent_id": "0",
"cat_name": "Category 1"
}
]
And a second array - $topics:
[
{
"cat_id": "351",
"parent_id": "350",
"cat_name": "Topic 1",
},
{
"cat_id": "352",
"parent_id": "350",
"cat_name": "Topic 2",
}
]
And I want this:
[
{
"cat_id": "350",
"parent_id": "0",
"cat_name": "Category 1",
"topics": [
{
"cat_id": "351",
"parent_id": "350",
"cat_name": "Topic 1",
},
{
"cat_id": "352",
"parent_id": "350",
"cat_name": "Topic 2",
}
]
}
]
I'm thinking that an embeded foreach loop might be the answer, but still sifting through all of the PHP array functions to try an figure out if there is an existing function that just does this: http://php.net/manual/en/ref.array.php
"parent_id"s and set that array to the value of the first array's"topics".swing_hammer()andtwist_screwdriver()instead of flailing around forbuild_a_house()"cat_id": "350",, in the expected array"cat_id": "222",Why?