Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function array_set_depth($array, $depth = -1)
- {
- $subdepth = $depth + 1;
- if ($depth < 0) {
- foreach ($array as $key => $subarray) {
- $temp[$key] = array_set_depth(($subarray), $subdepth);
- }
- }
- if ($array['hasChildren'] && isset($array['children'])) {
- foreach ($array['children'] as $key => $subarray) {
- $temp[$key] = array_set_depth($subarray, $subdepth);
- }
- $array['children'] = $temp;
- }
- $array['depth'] = $depth;
- return $array;
- }
- function array_set_depth($array, $depth = -1)
- {
- $subdepth = $depth + 1;
- if ($depth < 0) {
- foreach ($array as $key => $subarray) {
- $temp[$key] = array_set_depth(($subarray), $subdepth);
- }
- }
- if ($array['hasChildren'] && isset($array['children'])) {
- foreach ($array['children'] as $key => $subarray) {
- $temp[$key] = array_set_depth($subarray, $subdepth);
- }
- $array['children'] = $temp;
- }
- $array['depth'] = $depth;
- return $array;
- }
- function array_set_depth($array, $depth = -1)
- {
- $subdepth = $depth + 1;
- if ($depth < 0) {
- foreach ($array as $key => $subarray) {
- $temp[$key] = array_set_depth(($subarray), $subdepth);
- }
- }
- if ($array['hasChildren'] && isset($array['children'])) {
- foreach ($array['children'] as $key => $subarray) {
- $temp[$key] = array_set_depth($subarray, $subdepth);
- }
- $array['children'] = $temp;
- }
- $array['depth'] = $depth;
- return $array;
- }
- function array_set_depth($array, $depth = -1)
- {
- $subdepth = $depth + 1;
- if ($depth < 0) {
- foreach ($array as $key => $subarray) {
- $temp[$key] = array_set_depth(($subarray), $subdepth);
- }
- }
- if ($array['hasChildren'] && isset($array['children'])) {
- foreach ($array['children'] as $key => $subarray) {
- $temp[$key] = array_set_depth($subarray, $subdepth);
- }
- $array['children'] = $temp;
- }
- $array['depth'] = $depth;
- return $array;
- }
- $b = array_set_depth($a);
- print_r($b);
- function array_set_depth($array, $depth = -1)
- {
- $subdepth = $depth + 1;
- if ($depth < 0) {
- foreach ($array as $key => $subarray) {
- $temp[$key] = array_set_depth(($subarray), $subdepth);
- }
- return $temp;
- }
- $array['depth'] = $depth;
- if ($array['hasChildren'] && isset($array['children'])) {
- foreach ($array['children'] as $key => $subarray) {
- $temp[$key] = array_set_depth($subarray, $subdepth);
- }
- unset($array['children']);
- $array['children'] = $temp;
- }
- return $array;
- }
- function setDepth(&$a, $depth)
- {
- $a['depth']=$depth;
- foreach($a as $key=>$value)
- {
- if (is_array($value))
- setDepth($a[$key], $depth+1);
- }
- }
- function setDepth(&$a, $depth = -1)
- {
- if (($depth > -1) && !($depth % 2))
- $a['depth']= $depth / 2;
- foreach($a as $key=>$value)
- {
- if (is_array($value))
- setDepth($a[$key], $depth+1);
- }
- }
- setDepth($a);
- print_r($a);
- function setdepth($arr, $depth = 0)
- {
- foreach ($arr as $key => $val)
- {
- $arr[$key]['depth'] = $depth;
- if ($arr[$key]['hasChildren'])
- {
- setdepth(&$arr[$key]['children'], $depth+1);
- }
- }
- }
- $arr[0] = $website;
- setdepth(&$arr, 0);
Add Comment
Please, Sign In to add comment