This article mainly introduces php's methods for implementing recursion and unlimited classification, and involves php's recursive operation skills. if you need them, refer to the example in this article to describe php's methods for implementing recursion and unlimited classification, share it with you for your reference. The specific implementation method is as follows:
<? Phpecho""; $ Area = array ('id' => 1, 'region' => 'Beijing', 'pid '=> 0 ), array ('id' => 2, 'area '=> 'Guangxi', 'pid '=> 0), array ('id' => 3, 'area '=> 'Guangdong', 'pid '=> 0), array ('id' => 4, 'area' => 'Fujian ', 'pid '=> 0), array ('id' => 11, 'area' => 'chaoyang District ', 'pid' => 1 ), array ('id' => 12, 'area '=> 'haidian District', 'pid '=> 1), array ('id' => 21, 'area '=> 'nanning city', 'pid '=> 2), array ('id' => 45, 'area' => 'Fuzhou city ', 'pid '=> 4), array ('id' => 113, 'area' => 'Asian games cune', 'pid '=> 11 ), array ('id' => 115, 'area '=> 'Olympic cune', 'pid' => 11), array ('id' => 234, 'area '=> 'Wuming County', 'pid '=> 21); function t ($ arr, $ pid = 0, $ lev= 0) {static $ list = array (); foreach ($ arr as $ v) {if ($ v ['pid '] = $ pid) {echo str_repeat ("", $ lev ). $ v ['region']."
"; // Output here, to see the effect $ list [] = $ v; t ($ arr, $ v ['id'], $ lev+ 1 );}} return $ list;} $ list = t ($ area); echo"
"; Print_r ($ list);?>
I hope this article will help you with php programming.