title: Confused between array and objects in Laravel
body: <p>I'm learning Laravel and it uses OOPS concepts. Now I'm finding it hard to understand the real difference between array and objects. I actually know what an array and object is.</p>
  
  <p>Array can hold more than one variable where as an object is an independent entity which has its own arguments and methods. We usually use foreach loop to loop through them.</p>
  
  <p>In laravel, data is returned in the form of model instance as object. When the query response has multiple results, then data is returned in the form of an array which contains objects. I was trying to understand Collection Class used in laravel. </p>
  
  <p>Codebright reference says</p>
  
  <blockquote>
    <p>The Collection class itself, is merely a wrapper for an array of objects, but has a bunch of other interesting methods to help you pluck items out of the array.</p>
  </blockquote>
  
  <p>Now coming back to my confusion. I was using different methods like <code>all()</code> and <code>first()</code> methods to fetch the result. But sometimes when i used arrow (<code>-&gt;</code>) to fetch the data using a foreach loop, from an object (contained in an array), it showed an error that says something like it is a non object. Then I used square brackets and the data was displayed.</p>
  
  <p>I know we use <code>[]</code> to fetch data from arrays and we use <code>-&gt;</code> to fetch data from objects. But I'm still confused about Laravel. Can someone clearly state the difference between them in reference to Collection class used in Laravel?</p>
  
  <p>Edit:: The confusion began while using this code:</p>
  
  <pre><code>foreach($self_conversations as $self_conversations_fetch){
      //fetching each conversation id
      $conversation_id = Conversation::find($self_conversations_fetch-&gt;conversation_id);
      $user_id = array();
  
  //fetching each conversation member's id
      foreach($conversation_id-&gt;conversationsMember as $conversationmembers)
          $user_id[] = $conversationmembers-&gt;user_id;
  
          $self_id = User::where('email', Session::get('email'))-&gt;first()-&gt;id;
          $self_id_array = array($self_id);
          $friend_id_array = array_diff($user_id, $self_id_array);
  
          foreach($friend_id_array as $friend_id) array_push($friend_ids, $friend_id);
  
      $conversations_reply_obj = ConversationReply::where('conversation_id', $self_conversations_fetch-&gt;conversation_id)-&gt;orderBy('updated_at', 'desc')-&gt;first();
  
      $conversations_reply[] = $conversations_reply_obj['reply'];
  }
  </code></pre>
  
  <p>As you can see, i have used square brackets to fetch the data(in the last line).</p>
  
  <pre><code>$conversations_reply[] = $conversations_reply_obj['reply'];
  </code></pre>
  
  <p>i was expecting arrow to work here</p>