3 回答

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以通過以下方式獲取第二維的大?。?/p>
$ncols = count($people[$row]);
你的代碼可能是這樣的:
<?php
$people = array(
array("Rodrick","Java","PHP"),
array("Jane","Python","Javascript"),
array("Tom","Python","R"),
array("Wangari","Ruby","Kotlin"),
);
for($row = 0 ; $row < count($people) ; $row++){
echo "The Programmers ".$row;
echo "<ol>";
$ncols = count($people[$row]);
for($col = 0 ; $col < $ncols ; $col++){
echo "<li>".$people[$row][$col]."</li>";
}
echo "</ol>";
}
?>

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊
列數(shù)在此根據(jù)第一行確定。
$numberOfColumns = count(reset($people));
該計(jì)算可用于數(shù)值數(shù)組,也可用于關(guān)聯(lián)數(shù)組。

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
你真的需要知道嵌套數(shù)組的大小嗎?
這是foreach使用過的解決方案:
$people = array(
array("Rodrick","Java","PHP"),
array("Jane","Python","Javascript"),
array("Tom","Python","R"),
array("Wangari","Ruby","Kotlin"),
);
foreach($people as $human){
echo "<ol>";
foreach($human as $data){
echo "<li>".$data."</li>";
}
echo "</ol>";
}
- 3 回答
- 0 關(guān)注
- 188 瀏覽
添加回答
舉報(bào)