複製程式碼 程式碼如下:
類貓
{
public $data;
公共函數 __construct()
{
@include "data.php";
$this->data = $class;
}
公用函數 CreateSortLevel($fatherlevel)
{
🎜> if(is_array(this$->data))
{
$fast_level = array();
foreach($this->data as $value)
if(strlen($value["sortlevel"]) == 3)
$fast_level[] = $值[“排序級別”];
}
$max_fast_level = max($fast_level);
未已設定($fast_level);
$sub = ceil($max_fast_level) + 1;
switch(strlen($sub))
案例 1:
return "00{$sub }";
休息中;
return "0{$sub}";
休息中;
return $sub;
休息中;
其他
{
}
}
if(eregi("^".$fatherlevel.".{3}$",$val["sortlevel"]))
{
}
}
if(is_array ($等級) )
{
$max_two_level = max two_level,-3)) + 1;
switch(strlen($sub) ))
{為
ubstr($max_two_level,0,strlen($max_two_level)-1).$sub;
:
return substr($ max_two_level ,0,strlen($max_two_level)-2).$sub;
return substr($max_two_level,0,strlen($max) _)二樓)-3 )。 其他
{
返回$fatherlevel函數orders()
{
$op = $this->data
$this->array_usort($op) }
公共函數add_cat( $sortname,$sortlevel)
{
$data = time();
$arr = $arr = (
"排序名稱" => $排序名稱,
this->CreateSortLevel($sortlevel)
)
);
$rs = $this->data + $arr;
$this->add_wirte($rs);
}
導管函數 array_usort(&$array)
{
$args = func_get_args();
for($i=1,$cmd='',$size=count($args);$i ;
$order = "";
$con = "@strcmp($a['$args[$num]'],$b['$args[$num]'])";
while(++$i == SORT_NUMERIC)
{
args[$num]']-$b['$args[$num]'])";
}
{
$order = "- 1 * else if(is_string($ args[$i]))
{
$i--;
休息;
}
}
$cmd .= "if($num = $con)return $ order$num;else ";
if($order != '')
i++;
}
}
$a,$b',"$cmd return 0;"));
}
公共函數 wirte($sortname,$sortlevel)
{
$array = " $array .='$class = array'."rn(rn";
$array .='mŠ"'.S.>o. array .= ' ('."rn";
$array .= ' $array .= ' " sortlevel" => "'.$this->CreateSortLevel($sortlevel).'"'."rn";
$array .= ' ”;
file_put_contents("data.php",$array);
}
公用函數 add_wirte($rs)
{
$array = " $array .='$class = array'."rn";
foreach($rs as $key=>$value)
{
{
$array .= ' "'.$key.'" => array'."rn";
$array .= ' ('."rn";
"'.",rn";
$array .= ' "sortlevel" => "'.$value .=' ),';
}
$array = substr($array,0,-1);
$array .= " rn)rn?>";
file_put_contents("data.php",$array);
}
}
$cat = new cat();
if($_GET["action"] == "add")
{
if(strlen($_POST["sortname"]) alert("請新增分類名稱")';
echo '<script>location.href="/cat.php?action=tpl"</script>';
退出;
}
if(file_exists("data.php")) echo '<script>alert("新增成功")</script>';
echo '<script>location.href="/cat.php"</script>';
退出;
}
其他
{. ;
echo '<script>alert("新增成功")</script>';
echo '<script>location.href="/cat.php"</script>';
退出;
退出;
}
} ';"rn";
echo 'rn";
echo ' '.. ="submit" name="Submit" value="提交" />';
echo "";
exit;
$level = strlen(substr($value['sortlevel'],0,-3));
for($i = 0; i++)
{
echo "-";
}
?>
以上就介紹了 使用PHP數組實現無限分類,不使用資料庫,不使用遞歸,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。