This article mainly introduces php's methods for implementing recursion and unlimited classification, and involves php's recursive operation skills. For more information, see
This article mainly introduces php's methods for implementing recursion and unlimited classification, and involves php's recursive operation skills. For more information, see
The examples in this article describe how php implements recursion and unlimited classification, and share them 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.