// return $this->doors; // echo '<pre>'; // print_r($this->doors); // echo '</pre>'; } return $this->doors; } public function result() { return $this->parse(1); } } ob_start(); $room = new Room(50); echo '<pre>'; print_r($room->result()); echo '</pre>'; $output = ob_get_clean(); $filename = '21.html'; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!($handle = fopen($filename, 'w'))) { echo "Cannot open file ({$filename})"; exit; } //prepare the finish statements // Write $somecontent to our opened file. if (fwrite($handle, $output) === FALSE) {
} class Room { private $doors = array(); function __construct($number) { for ($i = 1; $i <= $number; $i++) { $this->doors[] = new Door(); } } public function parse($step) { for ($i = $step; $i <= count($this->doors); $i += $step) { $this->doors[$i - 1]->toggle(); } if ($step <= count($this->doors)) { $this->parse($step + 1); } else { echo '<pre>'; print_r($this->doors); echo '</pre>'; } } public function result() { return $this->parse(1); } } $room = new Room(50); $room->result();