Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:46:23+00:00 2026-05-23T15:46:23+00:00

Here is my code to list all category as a list item: if ($xml)

  • 0

Here is my code to list all category as a list item:

if ($xml) {
    foreach($xml->children() as $IRXML) {                                                                           // SHOW ONLY 5 NEWS ITEMS

        foreach($IRXML->children() as $newsrelease) {                                               // EACH NEWSRELEASE IS ONE SUBCHILD

            // echo "   <div class='news-image'>";
            // echo "<img src='/wp-content/themes/bby/images/news-story-01.jpg' alt=''>";
            // echo "</div>";

            $categories = $newsrelease->Categories;
            foreach($categories->children() as $category) {
                if ($category != "NA") {
                    echo "<li class='category ".$category."'>".$category."</li> ";
                }
            }

        }
    }

}

What I wanted to do is only to display a category without duplicating it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:46:24+00:00Added an answer on May 23, 2026 at 3:46 pm
    $list_cache = array();
    
    if ($xml)
    {
        foreach($xml->children() as $IRXML) 
    
        foreach($IRXML->children() as $newsrelease) 
        {
    
            $categories = $newsrelease->Categories;
    
            foreach($categories->children() as $category)
            {
                if ($category != "NA")
                {
                    $print_category = "<li class='category ".$category."'>".$category."</li> ";
    
                    if( !in_array($print_category, $list_cache) )    //check if you've stored in previously in this array. In such case, in_array will return true. 
                    {
                        $list_cache[] = $print_category;
                        echo $print_category;
                    }
                }
            }
        }
    }
    

    Check out the in_array function from the documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code: ProductList products = xxx.GetCarProducts(productCount); List<CarImageList> imageList = new List<CarImageList>(); foreach(Product p
Here is my code: let avg l = List.fold_left ( +. ) 0. l
Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= cmd.exe commandsBuffer ::=
Here's my code: Event thisEvent = (from i in list where (i.eventID == eventID)
I am looking for T-SQL code to list all tables in all databases in
Code can be found here: http://www.myhorizon.ca/client_central/sortable_test.php Hello folks of Stackoverflow, I have a list
I am using Entity Framework 4.1 code first . Here is my Category class:
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code from MSDN . I don't understand why the work isn't just
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.