title: Outputting data using a collection class PHP
body: <p>I have created a collection class and then a class car. I'm adding instances of the car class too the collection class. In my class car I can add a description, top speed ect to each car. I would like to be able to loop through all of the cars and output the description and top speed. Sorry for the a lot of code I hope you understand what I'm trying to achieve. I have added a comment in the bottom code/class of where I would like to output these things.</p>
  
  <p>Collection class:</p>
  
  <pre><code>&lt;?php 
   class ObjectCollection  
  {  
      //This is an array to hold line items
      private $items_array ;
  
      private $itemCounter; //Count the number of items
  
      public function __construct() {
          //Create an array object to hold line items
          $this-&gt;items_array = array();
          $this-&gt;itemCounter=0; 
       }
  
      public function getItemCount(){
          return $this-&gt;itemCounter;
      }  
  
  
      // This will add a new line object to line items array
      public function addItem($item) {
         $this-&gt;itemCounter++;
         $this-&gt;items_array[] = $item;
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>My Car Class:
      
  
  <pre><code>class car {
    private $id;
    private $description;
    private $topspeed;
    private $price;
  
    public function __construct($id, $price) {
         $this-&gt;id = $id;
         $this-&gt;price = $price;
    }
  
    public function setDescription($description) {
              $this-&gt;description = $description ;
    }
  
    public function getDescription() {
        return $this-&gt;description ;
    }
  
    public function setTopspeed($topspeed) {
              $this-&gt;topspeed = $topspeed;
   }
  
  public function getTopspeed() {
        return $this-&gt;topspeed ;
   }
  
   //other methods here
  
  } //End of class
  
  ?&gt;
  </code></pre>
  
  <p>CLASS where I'm looping through the <code>ObjectCollection</code>:</p>
  
  <pre><code> $car = new car("1",400);
   $car2 = new car("2",4400);
  
   $car-&gt;setDescription("A really fast car ");
   $car2-&gt;setDescription("A really slow car ");
  
  
  
   $ObjColl = new ObjectCollection();
   $ObjColl-&gt;addItem($car1);
   $ObjColl-&gt;addItem($car2);
  
  
  
   for($i = 0;$ObjColl-&gt;getItemCount();$i++){
     //CODE NEED TO BE ADDED TO OUTPUT TOPSPEED AND DESCRIPTION ECT????
  }
  </code></pre>