Created
December 17, 2015 18:15
-
-
Save VictorFursa/a3fb45b88b361261ab10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //phpinfo(); exit; | |
| header('Content-Type: text/html; charset=utf-8'); | |
| $a = array( | |
| array( | |
| "id" => 1, | |
| "parent_id" => 0, | |
| "name" => "Электротовары" | |
| ), | |
| array( | |
| "id" => 2, | |
| "parent_id" => 1, | |
| "name" => "Компьтеры" | |
| ), | |
| array( | |
| "id" => 3, | |
| "parent_id" => 1, | |
| "name" => "Бытовая техника" | |
| ), | |
| array( | |
| "id" => 4, | |
| "parent_id" => 2, | |
| "name" => "Acer XD5732" | |
| ), | |
| array( | |
| "id" => 5, | |
| "parent_id" => 3, | |
| "name" => "Холодильник" | |
| ), | |
| array( | |
| "id" => 6, | |
| "parent_id" => 3, | |
| "name" => "Микроволновка" | |
| ), | |
| array( | |
| "id" => 7, | |
| "parent_id" => 0, | |
| "name" => "Автомобили" | |
| ), | |
| array( | |
| "id" => 8, | |
| "parent_id" => 7, | |
| "name" => "Pego 206" | |
| ) | |
| ); | |
| function get_child($id, $data,$x){ | |
| $childrens = array(); | |
| foreach($data as $row){ | |
| if($row['parent_id'] == $id){ | |
| if($x <=$id){ | |
| $x = $x+1; | |
| for($i=0;$i < $x;$i++){ | |
| echo "*"; | |
| } | |
| } | |
| echo $row['name'] . "<br>"; | |
| $arr = array( | |
| "name" => $row["name"], | |
| "childrens" => get_child($row['id'], $data,$x) | |
| ); | |
| $childrens[] = $arr; | |
| } | |
| } | |
| return $childrens; | |
| } | |
| get_child(0, $a,1); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment