title: Split an array into mutiple arrays based on a value - PHP
body: <p>What I've tried so far : I have an array as shown below, what i wanted to do is, create multiple arrays based on the value <code>BEGIN_DAY</code>:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; BEGIN_DAY
              [1] =&gt; 15
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; 20130701
              [1] =&gt; 4
              [2] =&gt; 4
              [3] =&gt; 3060
              [4] =&gt; 1
          )
  
      [2] =&gt; Array
          (
              [0] =&gt; 20130702
              [1] =&gt; 270
              [2] =&gt; 757
              [3] =&gt; 13812810
              [4] =&gt; 4
          )
  
      [3] =&gt; Array
          (
              [0] =&gt; 20130703
              [1] =&gt; 5
              [2] =&gt; 123
              [3] =&gt; 3894971
              [4] =&gt; 2
          )
  
      [4] =&gt; Array
          (
              [0] =&gt; 20130704
              [1] =&gt; 290
              [2] =&gt; 478
              [3] =&gt; 5119617
              [4] =&gt; 1
          )
      [5] =&gt; Array
          (
              [0] =&gt; END_DAY
              [1] =&gt; 15
          )
      [6] =&gt; Array
          (
              [0] =&gt; BEGIN_DAY
              [1] =&gt; 16
          )
       [7] =&gt; Array
          (
              [0] =&gt; 20130704
              [1] =&gt; 290
              [2] =&gt; 478
              [3] =&gt; 5119617
              [4] =&gt; 1
          )
  </code></pre>
  
  <p>and so on ...
  I want to split this array into multiple different arrays when ever it begin with <code>BEGIN_DAY</code> so it should look like this:
  The first :</p>
  
  <pre><code> Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; BEGIN_DAY
              [1] =&gt; 15
          )
  
      [1] =&gt; Array
          (
              [0] =&gt; 20130701
              [1] =&gt; 4
              [2] =&gt; 4
              [3] =&gt; 3060
              [4] =&gt; 1
          )
  
      [2] =&gt; Array
          (
              [0] =&gt; 20130702
              [1] =&gt; 270
              [2] =&gt; 757
              [3] =&gt; 13812810
              [4] =&gt; 4
          )
  
      [3] =&gt; Array
          (
              [0] =&gt; 20130703
              [1] =&gt; 5
              [2] =&gt; 123
              [3] =&gt; 3894971
              [4] =&gt; 2
          )
  
      [4] =&gt; Array
          (
              [0] =&gt; 20130704
              [1] =&gt; 290
              [2] =&gt; 478
              [3] =&gt; 5119617
              [4] =&gt; 1
          )
      [5] =&gt; Array
          (
              [0] =&gt; END_DAY
              [1] =&gt; 15
          )
  </code></pre>
  
  <p>The second :</p>
  
  <pre><code>    [0] =&gt; Array
          (
              [0] =&gt; BEGIN_DAY
              [1] =&gt; 16
          )
      [1] =&gt; Array
          (
              [0] =&gt; 20130704
              [1] =&gt; 290
              [2] =&gt; 478
              [3] =&gt; 5119617
              [4] =&gt; 1
          )
  </code></pre>
  
  <p>What I've tried so far : </p>
  
  <pre><code>$days=array();
  $split_by='BEGIN_DAY';
  foreach ($day_all as $key =&gt; $value) {
      if($day_all[$key][0]==$split_by){
           $days=array_slice($day_all, 0,$split_by);
    }
  }
   var_dump($days);
  </code></pre>
  
  <p>Much Appreciated!</p>