@ 2015-09-16T14:02:03Z <?php
class Record {
protected $index=0; //page index
protected $pages=[]; //pages array
public function nextPage() {
$this->index++;
}
public function addRecord($key, $value) {
$this->pages[$this->index][$key] = $value;
}
public function getPage($index) {
if ($index > $this->index)
return NULL;
else
return $this->pages[$this->index];
}
}
class AdditiveRecord extends Record {
public function getSums($range) {
$sums = $this->pages[$range[0]];
$lim = ($range[1] <= $this->index) ? $range[1] : $this->index;
echo $lim;
for ($i = $range[0]+1;$i<=$lim;$i++) {
foreach($this->pages[$i] as $k=>$v)
$sums[$k] += $v;
}
return $sums;
}
}
$m = new AdditiveRecord();
for ($j = 1;$j<3;$j++) {
for ($i = 1;$i<10;$i++)
$m->addRecord($i,$j*10+$i);
$m->nextPage();
}
var_dump($m->getSums([0,2]));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.19 , 8.3.0 - 8.3.7 2
Warning: Undefined array key 2 in /in/rJpeH on line 27
Warning: foreach() argument must be of type array|object, null given in /in/rJpeH on line 27
array(9) {
[1]=>
int(32)
[2]=>
int(34)
[3]=>
int(36)
[4]=>
int(38)
[5]=>
int(40)
[6]=>
int(42)
[7]=>
int(44)
[8]=>
int(46)
[9]=>
int(48)
}
Output for 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.31 , 7.4.0 - 7.4.33 2
Notice: Undefined offset: 2 in /in/rJpeH on line 27
Warning: Invalid argument supplied for foreach() in /in/rJpeH on line 27
array(9) {
[1]=>
int(32)
[2]=>
int(34)
[3]=>
int(36)
[4]=>
int(38)
[5]=>
int(40)
[6]=>
int(42)
[7]=>
int(44)
[8]=>
int(46)
[9]=>
int(48)
}
Output for 7.3.32 - 7.3.33 2
Warning: Invalid argument supplied for foreach() in /in/rJpeH on line 27
array(9) {
[1]=>
int(32)
[2]=>
int(34)
[3]=>
int(36)
[4]=>
int(38)
[5]=>
int(40)
[6]=>
int(42)
[7]=>
int(44)
[8]=>
int(46)
[9]=>
int(48)
}
preferences:dark mode live preview
248.02 ms | 402 KiB | 378 Q