Skip to content

Instantly share code, notes, and snippets.

@ginsengs
Created March 30, 2017 15:53
Show Gist options
  • Save ginsengs/7c0d79b684b420ad958762dc896b047a to your computer and use it in GitHub Desktop.
Save ginsengs/7c0d79b684b420ad958762dc896b047a to your computer and use it in GitHub Desktop.
<?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