myAdBanner

2014年12月9日 星期二

計算陣列個數 count 用法

<?php
$data = array(
    "apples" =>
        array("red", "yellow", "pineapples"),
    "bananas" =>
        array("small", "medium", "big"),
    "vegs" =>
        array("potatoes", "carrots", "onions")
);

$rows = count($data,0);
$cols = (count($data,1)/count($data,0))-1;
print "There are {$rows} rows and {$cols} columns in the table!";
?>
There are 3 rows and 3 columns in the table!