I have two arrays as such: $cats=array( 'wedding-venues'=>array('1', '2', 'Wedding Venues'), 'wedding-caterers'=>array('1', '3', 'Wedding Caterers'), ); $subcats=array( 'banquet-halls'=>array('wedding-venues', 'Banquet Halls'), 'hotels'=>array('wedding-venues', 'Hotels'), 'general-caterers'=>array('wedding-caterers', 'Wedding Caterers'), ); Code (markup): And I have created a foreach loop which is meant to match $subcats to $cats: foreach($subcats as $index => $value) { if($value[0]==array_keys($cats)) { //print out the matching values; } } Code (markup): But this doesn't seem to work. Anyone got any ideas how to do this? It should just be as simple as that, but I can't figure out why that won't work!
Array_keys will create a array of keys, so you are comparing string to array. foreach($subcats as $index => $value) { echo $value[0]."<br>"; echo array_keys($cats)."<br>"; if($value[0]==array_keys($cats)) { //print out the matching values; } } This will output: wedding-venues Array wedding-venues Array wedding-caterers Array
foreach($subcats as $value) { foreach($cats as $donkey){ if($value == $donkey){ $match[] = value; } } foreach($match as $val){ print $val } } PHP: ??