Created
March 30, 2017 15:53
-
-
Save em7v/7c0d79b684b420ad958762dc896b047a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Tumba | |
{ | |
protected $box = []; | |
function __construct($yashik) | |
{ | |
for ($i = 0; $i < $yashik; $i++) { | |
$this->box[] = new Box(); | |
} | |
} | |
public function search($things){ | |
foreach ($this->box as $value){ | |
foreach ($value->getThings() as $thing){ | |
if ($things == $thing){ | |
return $value; | |
} | |
} | |
} | |
} | |
public function getBox() | |
{ | |
return $this->box; | |
} | |
} | |
class Box | |
{ | |
protected $things = []; | |
public function setThings(array $things = []) | |
{ | |
$this->things = $things; | |
} | |
public function getThings() | |
{ | |
return $this->things; | |
} | |
} | |
$Tumba = new Tumba(3); | |
echo '<pre>'; | |
$Tumba->getBox(); | |
$box = $Tumba->getBox(); | |
$box[0]->setThings(['футболка', 'штаны']); | |
$box[1]->setThings(['шорты', 'майка']); | |
print_r($Tumba->search('футболка')); | |
/* foreach ($box as $key => $value) { | |
echo '<hr> Номер коробки - ' . $key . '<br>'; | |
if ($value->getThings()) { | |
foreach ($value->getThings() as $thing) { | |
echo $thing . '<br>'; | |
} | |
} | |
else echo 'В коробке ничего нет'; | |
} */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment