/** * 無級遞歸分類 * @param int $assortPid 要查詢分類的父級id * @param mixed $tag 上下級分類之間的分隔符 * @return string $tree 返回的分類樹型結構結果 * */ function recursiveAssort($assortPid, $tag = '') { $assort = M('goods_class')->where("class_pid = $assortPid")->field('class_id, class_name')->select(); foreach ($assort as $value) { $tree .= '<option value="' . $value['class_id'] . '">' . $tag . $value['class_name'] . '</option>'; $tree .= recursiveAssort($value['class_id'], $tag . ' '); } return $tree; }