daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $data1 = [
  4.     'parent.child.field' => 1,
  5.     'parent.child.field2' => 2,
  6.     'parent2.child.name' => 'test',
  7.     'parent2.child2.name' => 'test',
  8.     'parent2.child2.position' => 10,
  9.     'parent3.child3.position' => 10,
  10. ];
  11.  
  12. function restructuring(array $arr) {
  13.     $data = [];
  14.     foreach ($arr as $k => $v) {
  15.         $fields = explode('.', $k);
  16.         $data[$fields[0]] = [
  17.             $fields[1] => [
  18.                 $fields[2] => $v
  19.             ]
  20.         ];
  21.     }
  22.    
  23.     return $data;
  24. }
  25.  
  26. $res = restructuring($data1);
  27.  
  28. print_r($res);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top