0
我是新來的PHP,我已經在php書中做了一個例子。在那裏,我得到了notice
。如何防止此通知?注意:Undefined抵消:2
<?php
require_once('AddingMachine.php');
$arrayofnumbers = array(100,200);
$objectname = new AddingMachine();
$objectname->addNumbers($arrayofnumbers);
?>
和
<?php
Class AddingMachine
{
private $total = 0;
function addNumbers(array $numbers)
{{
for($i=0;$i<=sizeof($numbers);$i++)
{
$this->total = $this->total + $numbers[$i];
}
echo $this->total;
}
}
}
在forloop中使用sizeof或count是一個巨大的性能影響。最好將數字定義爲一個變量並將其插入for循環。 – Goose 2015-05-24 05:23:57