title: php extract associate arrays
body: <p>There is an array which is hold the dynamic data. it changes randomly. I used <code>foreach()</code> loop to retrieve the <code>["space"]</code> <code>["channel"]</code> and <code>["Parker Dial String"]</code>.  </p>
  
  <pre><code>$parking_lot = array
  (
      0 =&gt; "bellcab-parked-call",
      2 =&gt; "Parking Extension   :  300",
      3 =&gt; "Parking Context     :  bellcab_call_parking_lot",
      4 =&gt; "Parking Spaces      :  3000-3099",
      5 =&gt; "Parking Time        :  0 sec",
      6 =&gt; "Comeback to Origin  :  no",
      7 =&gt; "Comeback Context    :  bellcab-parked-call-return",
      8 =&gt; "Comeback Dial Time  :  30 sec",
      9 =&gt; "MusicOnHold Class   :  ",
      10 =&gt; "Enabled             :  yes",
      11 =&gt; "Dynamic             :  no",
      12 =&gt; "",
      13 =&gt; "Parked Calls",
      14 =&gt; "------------",
      15 =&gt;  "Space               :  3000",
      16 =&gt;  "Channel             :  SIP/itc-vitel-inbound-00000ee4",
      17 =&gt;  "Parker Dial String  :  3004",
      18 =&gt; "",
      19 =&gt;   "Space               :  3001",
      20 =&gt;   "Channel             :  SIP/itc-vitel-inbound-00000ee7",
      21 =&gt;   "Parker Dial String  :  3004",
      22 =&gt;   "Space               :  3002",
      23 =&gt;   "Channel             :  SIP/itc-vitel-inbound-00000e82",
      24 =&gt;   "Parker Dial String  :  3004",
      25 =&gt; "",
      26 =&gt; "",
      27 =&gt; "--END COMMAND--"
  );
  
  foreach($parking_lot as $val)
  {
      $temp = explode(" : ", $val);
      if(isset($temp[1])){
          $new_array[trim($temp[0])][] = trim($temp[1]);
      }
  }
  print_r($new_array);
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>Array
  (
      [Parking Extension] =&gt; Array
          (
              [0] =&gt; 300
          )
  
      [Parking Context] =&gt; Array
          (
              [0] =&gt; bellcab_call_parking_lot
          )
  
      [Parking Spaces] =&gt; Array
          (
              [0] =&gt; 3000-3099
          )
  
      [Parking Time] =&gt; Array
          (
              [0] =&gt; 0 sec
          )
  
      [Comeback to Origin] =&gt; Array
          (
              [0] =&gt; no
          )
  
      [Comeback Context] =&gt; Array
          (
              [0] =&gt; bellcab-parked-call-return
          )
  
      [Comeback Dial Time] =&gt; Array
          (
              [0] =&gt; 30 sec
          )
  
      [MusicOnHold Class] =&gt; Array
          (
              [0] =&gt;
          )
  
      [Enabled] =&gt; Array
          (
              [0] =&gt; yes
          )
  
      [Dynamic] =&gt; Array
          (
              [0] =&gt; no
          )
  
      [Space] =&gt; Array
          (
              [0] =&gt; 3000
              [1] =&gt; 3001
              [2] =&gt; 3002
          )
  
      [Channel] =&gt; Array
          (
              [0] =&gt; SIP/itc-vitel-inbound-00000ee4
              [1] =&gt; SIP/itc-vitel-inbound-00000ee7
              [2] =&gt; SIP/itc-vitel-inbound-00000e82
          )
  
      [Parker Dial String] =&gt; Array
          (
              [0] =&gt; 3004
              [1] =&gt; 3004
              [2] =&gt; 3004
          )
  
  )
  </code></pre>
  
  <p>The desired output is like this</p>
  
  <pre><code>Array
  (
     Array(
           [Space] =&gt; 3000
           [Channel] =&gt; SIP/itc-vitel-inbound-00000ee4
           [Parker Dial String] =&gt; 3004
          )
     Array(
           [Space] =&gt; 3001
           [Channel] =&gt; SIP/itc-vitel-inbound-00000ee7
           [Parker Dial String] =&gt; 3004
          )
     Array(
           [Space] =&gt; 3002
           [Channel] =&gt; SIP/itc-vitel-inbound-00000e82
           [Parker Dial String] =&gt; 3004
          )
  )
  </code></pre>