title: Working with multidimensional array and objects in php
body: <p>I already posted a <a href="https://stackoverflow.com/questions/1549420/simple-formatting-of-multidimensional-array-from-mysql-in-php">similar</a> 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:</p>
  
  <p>So, I have an array similar to this:  </p>
  
  <pre><code>array(10) {
    [0]=&gt;
    object(VO)#6 (35) {
      ["eventID"]=&gt;
      string(1) "1"
      ["eventTitle"]=&gt;
      string(7) "EVENT 1"
      ["artistID"]=&gt;
      string(1) "1"
      ["artistName"]=&gt;
      string(8) "ARTIST 1"
      ["artistDescription"]=&gt;
      string(20) "ARTIST 1 description"
      // etc.
    }
    [1]=&gt;
    object(VO)#7 (35) {
      ["eventID"]=&gt;
      string(1) "1"
      ["eventTitle"]=&gt;
      string(7) "EVENT 1"
      ["artistID"]=&gt;
      string(1) "2"
      ["artistName"]=&gt;
      string(8) "ARTIST 2"
      ["artistDescription"]=&gt;
      string(20) "ARTIST 2 description"
      // etc.
    }
    [2]=&gt;
    object(VO)#8 (35) {
      ["eventID"]=&gt;
      string(1) "1"
      ["eventTitle"]=&gt;
      string(7) "EVENT 1"
      ["artistID"]=&gt;
      string(1) "3"
      ["artistName"]=&gt;
      string(8) "ARTIST 3"
      ["artistDescription"]=&gt;
      string(20) "ARTIST 3 description"
      // etc.
    }
    [3]=&gt;
    object(VO)#9 (35) {
      ["eventID"]=&gt;
      string(1) "2"
      ["eventTitle"]=&gt;
      string(7) "EVENT 2"
      ["artistID"]=&gt;
      string(1) "5"
      ["artistName"]=&gt;
      string(8) "ARTIST 5"
      ["artistDescription"]=&gt;
      string(20) "ARTIST 5 description"
      // etc.
    }
    [4]=&gt;
    object(VO)#10 (35) {
      ["eventID"]=&gt;
      string(1) "2"
      ["eventTitle"]=&gt;
      string(7) "EVENT 2"
      ["artistID"]=&gt;
      string(1) "7"
      ["artistName"]=&gt;
      string(8) "ARTIST 7"
      ["artistDescription"]=&gt;
      string(20) "ARTIST 7 description"
      // etc.
    }
  //etc.
  }
  </code></pre>
  
  <p>And I need to format it in this way:</p>
  
  <pre><code>array(2) {
    [1]=&gt;
    object(VO)#6 (9) {
      ["eventID"]=&gt;
      string(1) "1"
      ["eventTitle"]=&gt;
      string(7) "EVENT 1"
      ["artists"]=&gt;
      array(3) {
        [1]=&gt;
        array(2) {
          ["artistName"]=&gt;
          string(8) "ARTIST 1"
          ["artistDescription"]=&gt;
          string(20) "ARTIST 1 description"
        }
        [2]=&gt;
        array(2) {
          ["artistName"]=&gt;
          string(8) "ARTIST 2"
          ["artistDescription"]=&gt;
          string(20) "ARTIST 2 description"
        }
        [2]=&gt;
        array(2) {
          ["artistName"]=&gt;
          string(8) "ARTIST 3"
          ["artistDescription"]=&gt;
          string(20) "ARTIST 3 description"
        }
      }
    }
    [2]=&gt;
    object(VO)#7 (9) {
      ["eventID"]=&gt;
      string(1) "2"
      ["eventTitle"]=&gt;
      string(7) "EVENT 2"
      ["artists"]=&gt;
      array(3) {
        [1]=&gt;
        array(2) {
          ["artistName"]=&gt;
          string(8) "ARTIST 5"
          ["artistDescription"]=&gt;
          string(20) "ARTIST 5 description"
        }
        [2]=&gt;
        array(2) {
          ["artistName"]=&gt;
          string(8) "ARTIST 7"
          ["artistDescription"]=&gt;
          string(20) "ARTIST 7 description"
        }
      }
    }
  }
  </code></pre>
  
  <p>Thanks for any help!</p>