title: PHP foreach array IDs
body: <p>I have a foreach loop that is supposed to loop through JSON and return the appropriate ID of each video listed in JSON using the Youtube api.
  Here is my code:</p>
  
  <pre><code>class Videos {
      private $mVideoUrl;
  
      function setVideoTitle($videoUrl){
          $this-&gt;mVideoUrl= $videoUrl;
      }
  
      function getVideoTitle(){
          return $this-&gt;mVideoUrl;
      }
  } 
  
  $jsonFile = file_get_contents($url);
  $jfo = json_decode($jsonFile);
  $items = $jfo-&gt;items;
  $vidArray = array();
  
  foreach ($items as $item){
      if(!empty($item-&gt;id-&gt;videoId)){
          $Videos = new Videos;
          $Videos-&gt;setVideoUrl($item-&gt;id-&gt;videoId);
          $id = $Videos-&gt;getVideoUrl();
          array_push($vidArray, $id);
      }
      echo $vidArray[0];
  }
  </code></pre>
  
  <p>Problem is, the array push is working correctly, but it is only adding the 1st ID in the list only for each loop iteration when i echo it. When I echo the $id variable, it prints all IDs just fine.</p>
  
  <p>Ultimately i want to be able to create an object for each video, storing it's ID and other information.</p>
  
  <p>I feel like this is a simple fix but i can't figure it out for the life of me.
  I would appreciate any help! 
  Also if i am going about this all wrong, advice is appreciated as well!</p>
  
  <p>Thanks!</p>