php如何獲取一維陣列的長度,使用php函式count(),或是sizeof();
示例如下:
$arr = Array("0","1","2","3","4");
echo count($arr);
// 輸出 5
$arr = array("A","B","C");
echo sizeof($arr);
//輸出3
多維陣列:
$arr=array(
0=>array("title" => "新聞1", "viewnum" => 123, "content" => "內容1"),
1=>array("title" => "新聞2", "viewnum" => 99, "content" => "內容2")
);
echo "不統計多維陣列:".count($arr,0); echo "或用sizeof為".sizeof($arr,0);
echo "";
echo "統計多維陣列:".count($arr,1);echo "或用sizeof為".sizeof($arr,1);
php如何獲取一維陣列的長度,使用php函式count(),或是sizeof();
示例如下:
$arr = Array("0","1","2","3","4");
echo count($arr);
// 輸出 5
$arr = array("A","B","C");
echo sizeof($arr);
//輸出3
多維陣列:
$arr=array(
0=>array("title" => "新聞1", "viewnum" => 123, "content" => "內容1"),
1=>array("title" => "新聞2", "viewnum" => 99, "content" => "內容2")
);
echo "不統計多維陣列:".count($arr,0); echo "或用sizeof為".sizeof($arr,0);
echo "";
echo "統計多維陣列:".count($arr,1);echo "或用sizeof為".sizeof($arr,1);