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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:09:16+00:00 2026-05-13T09:09:16+00:00

I already posted a similar problem and it was resolved, but now I’m trying

  • 0

I already posted a similar problem and it was resolved, but now I’m trying to work with array of objects and I’m not sure how to resolve this:

So, I have an array similar to this:

array(10) {
  [0]=>
  object(VO)#6 (35) {
    ["eventID"]=>
    string(1) "1"
    ["eventTitle"]=>
    string(7) "EVENT 1"
    ["artistID"]=>
    string(1) "1"
    ["artistName"]=>
    string(8) "ARTIST 1"
    ["artistDescription"]=>
    string(20) "ARTIST 1 description"
    // etc.
  }
  [1]=>
  object(VO)#7 (35) {
    ["eventID"]=>
    string(1) "1"
    ["eventTitle"]=>
    string(7) "EVENT 1"
    ["artistID"]=>
    string(1) "2"
    ["artistName"]=>
    string(8) "ARTIST 2"
    ["artistDescription"]=>
    string(20) "ARTIST 2 description"
    // etc.
  }
  [2]=>
  object(VO)#8 (35) {
    ["eventID"]=>
    string(1) "1"
    ["eventTitle"]=>
    string(7) "EVENT 1"
    ["artistID"]=>
    string(1) "3"
    ["artistName"]=>
    string(8) "ARTIST 3"
    ["artistDescription"]=>
    string(20) "ARTIST 3 description"
    // etc.
  }
  [3]=>
  object(VO)#9 (35) {
    ["eventID"]=>
    string(1) "2"
    ["eventTitle"]=>
    string(7) "EVENT 2"
    ["artistID"]=>
    string(1) "5"
    ["artistName"]=>
    string(8) "ARTIST 5"
    ["artistDescription"]=>
    string(20) "ARTIST 5 description"
    // etc.
  }
  [4]=>
  object(VO)#10 (35) {
    ["eventID"]=>
    string(1) "2"
    ["eventTitle"]=>
    string(7) "EVENT 2"
    ["artistID"]=>
    string(1) "7"
    ["artistName"]=>
    string(8) "ARTIST 7"
    ["artistDescription"]=>
    string(20) "ARTIST 7 description"
    // etc.
  }
//etc.
}

And I need to format it in this way:

array(2) {
  [1]=>
  object(VO)#6 (9) {
    ["eventID"]=>
    string(1) "1"
    ["eventTitle"]=>
    string(7) "EVENT 1"
    ["artists"]=>
    array(3) {
      [1]=>
      array(2) {
        ["artistName"]=>
        string(8) "ARTIST 1"
        ["artistDescription"]=>
        string(20) "ARTIST 1 description"
      }
      [2]=>
      array(2) {
        ["artistName"]=>
        string(8) "ARTIST 2"
        ["artistDescription"]=>
        string(20) "ARTIST 2 description"
      }
      [2]=>
      array(2) {
        ["artistName"]=>
        string(8) "ARTIST 3"
        ["artistDescription"]=>
        string(20) "ARTIST 3 description"
      }
    }
  }
  [2]=>
  object(VO)#7 (9) {
    ["eventID"]=>
    string(1) "2"
    ["eventTitle"]=>
    string(7) "EVENT 2"
    ["artists"]=>
    array(3) {
      [1]=>
      array(2) {
        ["artistName"]=>
        string(8) "ARTIST 5"
        ["artistDescription"]=>
        string(20) "ARTIST 5 description"
      }
      [2]=>
      array(2) {
        ["artistName"]=>
        string(8) "ARTIST 7"
        ["artistDescription"]=>
        string(20) "ARTIST 7 description"
      }
    }
  }
}

Thanks for any help!

  • 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-13T09:09:17+00:00Added an answer on May 13, 2026 at 9:09 am

    A modified version of the answer to your previous question – will this do it?

    <?php
    $output = array();
    
    foreach($resultset as $event)
    {
    
       $eventId = $event->eventID;
       $artistId = $event->artistID;
    
       if (!isset($output[$eventId]))
       {
          $output[$eventId] = new stdClass();
    
          $output[$eventId]->eventTitle = $event->eventTitle;
          $output[$eventId]->eventID = $event->eventID;
       }
    
       if (!isset($output[$eventId]->artists)) $output[$eventId]->artists = array();
    
       $output[$eventId]->artists[$artistId] = array();
       $output[$eventId]->artists[$artistId]['artistID'] = $artistId;
       $output[$eventId]->artists[$artistId]['artistName'] = $event->artistName;
       $output[$eventId]->artists[$artistId]['artistDescription'] = $event->artistDescription;
    }
    echo '<pre>' . print_r($output,true) . '</pre>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[I just posted a similar question, but I'm not sure whether is actually got
I know that I was already posted similar question but I just can't find
I actually posted this question because I found similar questions but not a perfect
I already posted a similar question but i got told to try and solve
Sorry if something similar has been posted here already, but I couldn't really find
I have already posted something similar here but I would like to ask the
First of all: A quite similar problem has been posted and somehow solved already,
i have already posted a similar question here, but failed to get a response
I have already posted a question about this, but the situation has changed sufficiently
I know this question was already posted in StackOverflow but I either didnt understand

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.