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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:56:15+00:00 2026-06-04T04:56:15+00:00

I have an array of vendors called: $listOfVendors I loop through this array with

  • 0

I have an array of vendors called:

$listOfVendors 

I loop through this array with a foreach in my view.

<?php foreach($listOfVendors as $vendor):?>         

    <p class="vendor">
        <span class="vendor-title"><?php echo $vendor->name ?>(<?php echo $vendor->country ?>)</span>, 
        <?php echo $vendor->goods ?>, <a href="<?php echo $vendor->site_adres ?>" class="vendor-link"><?php echo $vendor->site_adres ?></a>
    </p>                                            

<?php endforeach ?> 

Each vendor object has the following properties:

vendors_Id, name, country, goods, site_address, activities_Id. The last one, activities_Id, is a FK to the table activities which has, for the time being, two types of activities: Dealers and Artists.

Now I want to add a header once for every type of vendor. So want to get something like:

Artist

Vendor1(DE), Eigen posters e.a. merchandise, http://www.linktosite.com

Dealer

Vendor2(BE), Toys, DVD’s, books, http://www.anotherlink.be

Vendor3(FR), Merchandise, http://www.anotherlink2link.be

How do I do this?
I just can’t seem to get my head around this seemingly simple thing.

Edit for Solution

Controller actvities -> function vendors

//Get the vendor information and add the needed headers
//Here I get all the vendors
if($listOfVendors = $this->atsusacon_model->get_records()) { 
    foreach($listOfVendors as $vendor) {
        $listOfVendorsByType[$vendor->activities_Id][] = $vendor;   
    }   
    $data['listOfVendorsByType'] = $listOfVendorsByType;    
    var_dump($listOfVendorsByType);
}   

View actvities/vendors

<section class="vendors-overview twelvecol clearBoth">

    <?php foreach($listOfVendorsByType as $activity):?> 

        <?php if ($activity[0]->activities_Id == 1) :?> 
            <h3>Artists</h3>
         <?php else :?>
            <h3>Dealers</h3>
        <?php endif ?>

        <?php foreach($activity as $vendor):?>      

            <p class="vendor">
                <span class="vendor-title"><?php echo $vendor->name ?>(<?php echo $vendor->country ?>)</span>, <?php echo $vendor->goods ?>, <a href="<?php echo $vendor->site_address ?>" class="vendor-link"><?php echo $vendor->site_address ?></a>
            </p>                                    

        <?php endforeach ?>         
    <?php endforeach ?> 

</section>

I could make it more dynamic but for now, this is exactly how it should be.

The var_dump of $listOfVendorsByType looks like this:

Var_dump($listOfVendorsByType)

  • 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-06-04T04:56:16+00:00Added an answer on June 4, 2026 at 4:56 am

    You have to create a nested array:

    <?php 
     foreach($listOfVendors as $vendor) {
       $vendorsByType[$vendor['activities_id']][] = $vendor;
     }
    ?> 
    

    Now you have just have to loop over this nested array using two foreach loops.

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

Sidebar

Related Questions

This is code that I have added in my vendors/xtcpdf.php file: <?php App::import('Vendor','tcpdf/tcpdf'); class
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
Hello i have array like this [0] => Array ( [ExamMonth] => Array (
I have this form that pops up in a modal window like so: <?php
I have an array like vendors = [{ Name: 'Magenic', ID: 'ABC' }, {
So I've got this hash here, and I have a loop. When the loop
Say I have an array such as this in Javascript: var cars = {
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array of strings, String[] data and it's 10 elements has value P

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.