3v4l.org

run code in 300+ PHP versions simultaneously
<?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; echo $index; 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]));
Output for git.master, git.master_jit, rfc.property-hooks
2 Warning: Undefined variable $index in /in/eFFek on line 26 Warning: Undefined array key 2 in /in/eFFek on line 28 Warning: foreach() argument must be of type array|object, null given in /in/eFFek on line 28 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) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
45.18 ms | 402 KiB | 8 Q