title: PHP - Create Arrays from Strings in another Array
body: <p>I've spent a long time on this problem, and I cannot for the life of me figure it out. Any help will be much appreciated!</p>
  
  <p>I have an array of strings, which I am using to get information from, i.e. the month of an event is hidden within the url (the string), and I want to cycle through all the urls and get the month, and other data out and make each data-piece it's own array. </p>
  
  <p>Here's the deal, I can do it twice successfully, but the third time I try to create an array, it breaks down. </p>
  
  <p>This code works: </p>
  
  <pre><code>    $months = array();
      $times = array();
  
      foreach ($ticketsLinks as $ticketsLink){
  
          //CREATE VENUE ARRAY
  
              // Delete all the way up to "-tickets-"
              $findMeA = '-tickets-'; 
              $posA = strpos($ticketsLink, $findMeA);
              $posA = $posA + 9;  
              $venue = substr($ticketsLink, $posA); 
  
              // Find the first number in the string - delete everything after that.
              $lengthA = strlen($venue);
  
              $parts = str_split($venue);
              $first_num = -1;
              $num_loc = 0;
              foreach ($parts AS $a_char) {
                      if (is_numeric($a_char)) {
                          $first_num = $num_loc;
                          break;
                      }
                          $num_loc++;
              }
              $posB = -$lengthA + $num_loc - 1;
              $venue = substr($venue, 0, $posB);
  
  
              // Replace dashes with spaces. 
              $venue = str_replace("-"," ",$venue);
  
              //Add value to venue's array
              $venues[] = $venue;
  
          //  CREATE TIME ARRAY
  
          $pos = strrpos($ticketsLink, '-');
          $pos = strlen($ticketsLink) - $pos - 1;
          $time = substr($ticketsLink, -$pos);
          $pos = strpos($time, '/');
          $time = substr($time, 0, $pos);
          $times[] = $time;
  
  
      }
  </code></pre>
  
  <p>This code does not: </p>
  
  <pre><code>$months = array();
      $times = array();
      $years = array();
  
      foreach ($ticketsLinks as $ticketsLink){
  
          //CREATE VENUE ARRAY
  
              // Delete all the way up to "-tickets-"
              $findMeA = '-tickets-'; 
              $posA = strpos($ticketsLink, $findMeA);
              $posA = $posA + 9;  
              $venue = substr($ticketsLink, $posA); 
  
              // Find the first number in the string - delete everything after that.
              $lengthA = strlen($venue);
  
              $parts = str_split($venue);
              $first_num = -1;
              $num_loc = 0;
              foreach ($parts AS $a_char) {
                      if (is_numeric($a_char)) {
                          $first_num = $num_loc;
                          break;
                      }
                          $num_loc++;
              }
              $posB = -$lengthA + $num_loc - 1;
              $venue = substr($venue, 0, $posB);
  
  
              // Replace dashes with spaces. 
              $venue = str_replace("-"," ",$venue);
  
              //Add value to venue's array
              $venues[] = $venue;
  
          //  CREATE TIME ARRAY
  
          $pos = strrpos($ticketsLink, '-');
          $pos = strlen($ticketsLink) - $pos - 1;
          $time = substr($ticketsLink, -$pos);
          $pos = strpos($time, '/');
          $time = substr($time, 0, $pos);
          $times[] = $time;
  
  
          //  CREATE YEAR ARRAY
  
          $pos = strrpos($ticketsLink, '-');
          $pos = strlen($ticketsLink) - $pos - 1;
          $year = substr($ticketsLink, -$pos);
          $pos = strpos($year, '/');
          $year = substr($year, 0, $pos);
          $years[] = $year;
  
  
      }
  </code></pre>
  
  <p>For the purposes of this example, I kept the code to get the year string and the time string exactly the same to show that that wasn't the problem. I've gone through the above code and tried to debug it - the only thing that's making it not work is when I push the year variable to the years array. </p>
  
  <p>--- UPDATED TO INCLUDE NEW INFORMATION -----</p>
  
  <p>Unfortunately, breaking apart the URL to get the requisite information is the best way to do this - the URLs are coming from a CSV feed. </p>
  
  <p>So, after the first foreach, then just for a test, I run a foreach loop through the $years array - </p>
  
  <pre><code>foreach($years as $year){
     echo $year;
   }
  </code></pre>
  
  <p>Eventually, the $years array will be passed to a mySQL database, but for now, I just want to make sure I'm processing the URL correctly. The resultant loop should look something like this: </p>
  
  <p>2014 
  2015
  2014
  2016</p>
  
  <p>Instead, I get nothing, and all the code after the first foreach (where I'm breaking down the URL), doesn't run. I have an echo at the bottom that echos "This code works!", and it doesn't print to the screen when I try to push values to the $years array.</p>