This is something I was sure I could knock out quick but I keep running into dead ends.
I am reworking the blog system in a CMS i wrote some time ago and I am working on adding multiple categories per blog entry. I'm working with two arrays, currently.
The first array is a result of a select query pulling all available categories for the drop down list from the category table:
Array
(
[0] => Array
(
[cat_id] => 1
[cat_title] => Uncategorized
)
[1] => Array
(
[cat_id] => 2
[cat_title] => General
)
)
left quite a bit off for brevity
The 2nd array is pulling the cat_id from the cross reference table
Array
(
[0] => Array
(
[cat_id] => 2
)
[1] => Array
(
[cat_id] => 24
)
)
I have a foreach loop to build the multiple select drop down box, and I've built it with a for loop just for testing.
Here's some pseudo code to demonstrate what I need
if (cat_id in 2nd array == cat_id in first array) {
$selected = 'selected';
}
I've tried using in_array, array_search, array_intersect, array_intersect_key. I just can't seem to work this out haha. Any help pointing me in the right direction will be greatly appreciated.