Results 1 to 1 of 1
Thread: comparing arrays
Aug 12, 2003, 10:38 #1
- Join Date
- Aug 2003
- Paterson, NJ USA
- 0 Post(s)
- 0 Thread(s)
Im a newb to php and programming in general, so bare with me guys
I have two arrays, one with categories, and the other with articles. If the category array has corresponding articles in the articles array, I want the category name and the corresponding articles to be displayed.
If a category has no articles, then it is not displayed.
Here's an example:
--You have two categories in the category array: news and sports
--You have four articles in the article array, all of which belong to the sports category
--OUPUT: The code only displays the sports category with the sports articles, since there are no news articles
The code I have written thus far displays the category name regardless of whether or not a category has corresponding articles. I'm having trouble writing a method that checks whether a category has articles.
Does anyone know of a way I can compare the two arrays to get the desired output? Any help would be greatly appreciated!
foreach($categories as $row1)
$cat_id = $row1['id'];
foreach($art_array as $row2)
$artcatid = $row2['category'];
if ($cat_id == $artcatid)
$title = $row2['headline'];