Php递归函数不能更深入地循环

时间:2016-10-25 14:00:59

标签: php html mysql

建筑应用程序将使用recrusive函数从数据库显示家谱。首先,一切都很棒但我的功能并没有更深入地循环并循环innerHeight String JS_GET_INNER_HEIGHT = "return window.innerHeight | 0;"; String JS_SCROLL_BOTTOM = "window.scroll(0, -1 >>> 1);"; // get the current scroll height Object innerHeight = driver.executeScript(JS_GET_INNER_HEIGHT); // set the size of the window driver.manage().window().setSize(new Dimension(width, height)); // wait for the scroll height to change new WebDriverWait(driver, 10) .until(drv -> !drv.executeScript(JS_GET_INNER_HEIGHT).equals(innerHeight)); // scroll to the bottom driver.executeScript(JS_SCROLL_BOTTOM);

这是我的例子:enter image description here

在上面的图片上,循环还必须循环child子项childAnnie

检查我的代码:

Steve

2 个答案:

答案 0 :(得分:1)

这是一个创建递归类别List

的简单示例
<?
     function buildTree($parent = 0, $treeArray = '') {

            if (!is_array($treeArray))
            $treeArray = array();

          $sql = "SELECT `cid`, `name`, `parent` FROM `category` WHERE 1 AND `parent` = $parent ORDER BY cid ASC";
          $query = mysql_query($sql);
          if (mysql_num_rows($query) > 0) {
             $treeArray[] = "<ul>";
            while ($row = mysql_fetch_object($query)) {
              $treeArray[] = "<li>". $row->name."</li>";
              $treeArray = buildTree($row->cid, $user_tree_array);
            }
            $treeArray[] = "</ul>";
          }
          return $treeArray;
        }
    ?>
 <ul>
    <?php
      $returnedData = buildTree();
      foreach ($returnedData as $returnedD) {
        echo  $returnedD;
      }
?>
</ul>

答案 1 :(得分:1)

recrusive_childrecursive_child?

进行递归调用
function recrusive_child($childs) {
            if(isset($childs)) {
                foreach ($childs as $child) {
                    echo "<li><a href='#'>".$child['username']."</a>";
                    if ($child['children']){
                        echo "<ul>";
                        recrusive_child($child['children']);
                        echo "</ul>";
                    }
                    echo "</li>";
                }
            }
        }