title: array_push() function not working in Laravel
body: <p>I'm developing a web application in Laravel. The below code is not from the application but gives you a simple idea of the problem I am having.</p>
  
  <p>The following code works</p>
  
  <pre><code>public $my_users = [];  //This is outside function
  
  $users = [];
  $users = User::all();
  $this-&gt;my_users = $users;
  </code></pre>
  
  <p>That's pretty simple, works fine. However, i want to be able to loop through all of the users and add ones of my choosing like so:</p>
  
  <pre><code>public $my_users = [];  //This is outside function
  
  $users = [];
  $all_users = User::all();
  foreach ($all_users as $user)
  {
      array_push($users, $user);
  }
  $this-&gt;my_users = $users;
  </code></pre>
  
  <p>Again, what I am doing here has no logic behind it, it's just an example. </p>
  
  <p>In this case both pieces of code should have the same result. However, the second piece of code isn't working. It seems to be the array_push function that isn't working here. is there any reason why this is? What am I to do here?</p>