Guest User

Untitled

a guest
Feb 13th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  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);
Add Comment
Please, Sign In to add comment