PHP中如何用sizeof()获取数组长度

2024-04-26

PHP中,可以使用sizeof()函数来获取数组的长度。例如:

$fruits = array("apple", "banana", "orange", "kiwi");
$length = sizeof($fruits);
echo "The length of the array is: " . $length;

上面的代码将输出:The length of the array is: 4。这表示数组$fruits中有4个元素。