Advertisement
SpeakeazyYT

Untitled

May 30th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. function addParent($array, $parent = null) {
  2.   $result = [];
  3.   foreach ($array as $key => $value) {
  4.     if (is_null($parent)) {
  5.       $result[] = $value['@attributes'];
  6.       $result = array_merge($result, addParent($value['category'], $value['@attributes']['code']));
  7.     } else {
  8.       $result[] = array_merge($value['@attributes'], ['code_parent' => $parent]);
  9.     }
  10.   }
  11.   return $result;
  12. }
  13.  
  14. $result = addParent($getSection);
  15. print_r($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement