我正在尝试计算每个盒子的体积,但我不断遇到错误,我不知道如何修复它。一切似乎都是正确的,我遵循了书中的例子。
这是它在这段代码中给我的错误:
“注意:未定义的偏移量:第 16 行 C:\wamp\www\BoxArray.php 中的 0”
<?php
$BoxMeasurements = array("sBox" => array("length" => 12, "width" => 10, "depth" => 2.5),
"mBox" => array("length" => 30, "width" => 20, "depth" => 4),
"lBox" => array("length" => 60, "width" => 40, "depth" => 11.5));
$BoxMeasurements = array_slice($BoxMeasurements, 0, 3);
echo "The box sizes are:";
for($i = 0; $i < count($BoxMeasurements); ++$i)
{
echo "$BoxMeasurements[$i]";
}
?>
当我尝试以另一种方式执行此操作时,出现此错误:
“解析错误:语法错误,意外 '=',在第 8 行的 C:\wamp\www\BoxArray.php 中期待 ')'”
<?php
$sBox = array("length" => 12, "width" => 10, "depth" = 2.5);
$mBox = array("length" => 30, "width" => 20, "depth" = 4);
$lBox = array("length" => 60, "width" => 40, "depth" => 11.5);
$dimension = array($sBox, $mBox, $lBox);
echo "$dimension[0][0]";
?>
有没有一种特殊的方法来调用变量/数组名称?