title: Prepend all array elements before a certain index in foreach loop
body: <p>I'm trying to create a function that will format the paths for my breadcrumbs. I have a basic idea of what I want to do but not sure how to implement it. I want to prepend everything in the array before a certain index inside of a loop and do it for every element of that array. I currently have the following code but the issue is that <code>$breadcrumbs[0]</code> is being defined by me, I need it to be automatically defined inside of PHP.</p>
  
  <pre><code>public static function formatBreadcrumbs ($path) {
      // Explode path into an array
      $breadcrumbs = explode('/', $path);
  
      $counter = 0;
  
      foreach ($breadcrumbs as $breadcrumb) {
          if ($breadcrumb !== $breadcrumbs[0]) {
              $formattedBreadcrumbs[] = $breadcrumbs[0] . '/' . $breadcrumb;
          }
      }
  
      var_dump($formattedBreadcrumbs);
  }
  </code></pre>
  
  <p>For example if I input an array such as:</p>
  
  <pre><code>$path = array(
      'documents',
      'text',
      'work'
  );
  </code></pre>
  
  <p>I would want my function to output:</p>
  
  <pre><code>$formattedPath = array(
      'documents',
      'documents/text',
      'documents/text/work'
  );
  </code></pre>
  
  <p>In theory, this seems pretty simple but the logic behind it is boggling my mind a bit. Any help would be great, Thanks!</p>