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 6156145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:33:33+00:00 2026-05-23T20:33:33+00:00

I have sent $data[‘items’] to my view which has created an array full of

  • 0

I have sent $data[‘items’] to my view which has created an array full of objects which I can echo with a foreach loop.

foreach($items as $row)
  {
    echo $row->NAME . " - " . $row->COLOUR . "<br>";
  }

what I want to do is echo them to the browser in groups with the name of the colour as a header tag then start the loop for that colour. I’m just not sure what type of loop to do or should I have a loop within a loop?

BLUE

-item 1

-item 3

RED

-item 2

-item 4

-item 5

  • 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-23T20:33:34+00:00Added an answer on May 23, 2026 at 8:33 pm
    $list = array();
    foreach($items as $row)
    {
      $list[$row->COLOUR][] = $row->NAME;
    }
    
    $header = null;
    foreach($list as $item)
    {
      if($header != $item->COLOUR)
      {
        echo '<h3>' . $item->COLOUR . '</h3>';
        $header = $item->COLOUR;
      }
      echo '- ' . $item->NAME . '<br />';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that is capturing data sent from a google LocalSearch API.
I have content on a webpage which is both sent from the server at
I would like to issue a submit from my form and have data sent
I have been investigating a problem with data sent to my PHP webservice with
I have a query on retrieving data sent as JSON from a JavaScript, inside
I have some simple questions, I have a client-server application and data sent on
I have a Controller method that needs to accept multipart/form-data sent by the client
I have a Java program that is constantly being sent UDP data from an
I have a form which sends data to a text file, but I'm trying
I have sent data to my jquery file and I tested the data string

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.