title: PHP dynamic multidimensional arrays - getting data into the right format
body: <p>I'm having a terrible time trying to massage an array of data into the format a third-party service requires. I can't change the way the data comes into the function so I need to manipulate it then send it off. I've managed to hack it into a state where its almost correct with the exception that it only takes the first value of the arrays and ignores the rest. I think this is because I'm overwriting the values but I don't know how to solve it. </p>
  
  <p>I'm pretty new to PHP and think I'm missing some core array methods or something here so any input would be greatly appreciated </p>
  
  <p>Data going into the function ($data)</p>
  
  <pre>
  Array (
      [checkbox_customfield_11363] => Array
          (
              [random unknown string] => Apple
              [random unknown string] => Orange
              [random unknown string] => Banana
          )
  
      [checkbox_customfield_11339] => Array
          (
              [random unknown string] => Peas
              [random unknown string] => Potatos
  
          )
  )
  </pre>
  
  <p>The function that should be massaging the data into the required format. The first foreach loop just removes the first part of the name of each array, It works as intended - might not be the cleanest though. Its the second foreach and below that I'm struggling with.</p>
  
  <pre><code>public function createCheckBoxField($data)
  {
      $checkbox_matches = array();
      foreach ($data as $key =&gt; $value) {
          if (preg_match("/checkbox/", $key)) {
              $newKey = explode('_', $key, 2);
              $checkbox_matches[$newKey[1]] = $value;
          }
      }
  
      $checkboxes = array();
      foreach ($checkbox_matches as $key1 =&gt; $value1) {
  
          foreach ($value1 as $test) {
              $checkboxes += [$key1 =&gt; [["value" =&gt; $test]]];
          }
      }
      return $checkboxes;
  }
  </code></pre>
  
  <p>Code currently returns</p>
  
  <pre>
  Array
  (
      [customfield_11363] => Array
          (
              [0] => Array
                  (
                      [value] => Apple
                  )
  
          )
  
      [customfield_11339] => Array
          (
              [0] => Array
                  (
                      [value] => Peas
                  )
  
          )
  
  )
  </pre>
  
  <p>I need it to be returning</p>
  
  <pre>
  Array
  (
      [customfield_11363] => Array
          (
              [0] => Array
                  (
                      [value] => Apple
                  )
              [1] => Array
                  (
                      [value] => Orange
                  )
              [2] => Array
                  (
                      [value] => Banana
                  )
  
          )
  
      [customfield_11339] => Array
          (
              [0] => Array
                  (
                      [value] => Peas
                  )
              [1] => Array
                  (
                      [value] => Potato
                  )
  
          )
  
  )
  </pre>