$dom = new \DOMdocument();
$dom->loadHtml('<div style="display: none">
<div class="goods_line 691433" data-type="goods_perfumery">
<div class="w60 left align-center">
691433</div>
<div class="w300 left">
<span class="goods_name">Туалетная вода Power Woman</span>
</div>
<div class="w150 left">2360.30 руб.</div>
<div class="w150 left">
<a class="button projectDetails" data-id="691433" data-href="" href="javascript:void(0);">Посмотреть товар</a>
</div>
<div class="w150 right align-center">
<a href="javascript:" data-id="691433" title="Добавить в корзину" class="tipsy_class bother_project"></a>
</div>
<div class="clear"></div><!-- /clear -->
</div>
</div>
<div style="display: none">
<div class="goods_line 691435" data-type="goods_perfumery">
<div class="w60 left align-center">
691435</div>
<div class="w300 left">
<span class="goods_name">Туалетная вода Be the Legend</span>
</div>
<div class="w150 left">3140 руб.</div>
<div class="w150 left">
<a class="button projectDetails" data-id="691435" data-href="" href="javascript:void(0);">Посмотреть товар</a>
</div>
<div class="w150 right align-center">
<a href="javascript:" data-id="691435" title="Добавить в корзину" class="tipsy_class bother_project"></a>
</div>
<div class="clear"></div><!-- /clear -->
</div>
</div>
<div style="display: none">
<div class="goods_line 30173" data-type="goods_perfumery">
<div class="w60 left align-center">
30173</div>
<div class="w300 left">
<span class="goods_name">Туалетная вода Eclat Homme</span>
</div>
<div class="w150 left">1999.90 руб.</div>
<div class="w150 left">
<a class="button projectDetails" data-id="30173" data-href="" href="javascript:void(0);">Посмотреть товар</a>
</div>
<div class="w150 right align-center">
<a href="javascript:" data-id="30173" title="Добавить в корзину" class="tipsy_class bother_project"></a>
</div>
<div class="clear"></div><!-- /clear -->
</div>
</div>');
$xpath = new \DOMXpath($dom);
$divs = $xpath->query("//div[starts-with(@class, 'goods_line')]");
$prices = [];
foreach ($divs as $div) {
$prices[$div->getAttribute('class')] = (float) $xpath->query("div[starts-with(@class, 'w150')]", $div)->item(0)->nodeValue;
}
arsort($prices, SORT_NUMERIC);
print_r(array_keys($prices));
$arr = [
8 => '',
9 => '',
10 => '',
11 => '',
12 => '12:30',
13 => '',
14 => '',
15 => '',
16 => '',
17 => '',
18 => '',
19 => '',
20 => '',
21 => '',
22 => '',
];
$values = array_flip(array_filter($arr));
$key = array_pop($values);
$dt = \DateTime::createFromFormat('H:i', $arr[$key]);
foreach ($arr as $k => $v) {
if (empty($v)) {
$v = clone $dt;
if ($k < $key) {
$v->sub(new \DateInterval('PT' . (($key-$k) * 30) . 'M'));
} else {
$v->add(new \DateInterval('PT' . (($k-$key) * 30) . 'M'));
}
$arr[$k] = $v->format('H:i');
}
}
P.S. Так же возможна ситуация, что массив содержит два или три значения, и нужно заполнить ячейки между ними.
//если надо сперва сделать сортировку
usort($arr, function($a, $b) {
return $a['sort'] === $b['sort'] ? 0 : ($a['sort'] < $b['sort'] ? -1 : 1);
});
$divisor = 100;
$res = [];
foreach ($arr as $subArr) {
$res[intdiv($subArr['sort'], $divisor)][] = $subArr;
}
//если php < 7, то меняем intdiv на floor и /
class Object
{
protected $di;
public function __construct($di)
{
$this->di = $di;
}
public function __get(string $name)
{
if (property_exists($this->di, $name)) {
return $this->di->$name;
} else {
throw new \Exception('бла бла');
}
}
public function __call(string $name, array $arguments)
{
if (method_exists($this->di, $name)) {
return $arguments ? $this->di->$name($arguments) : $this->di->$name();
} else {
throw new \Exception('бла бла');
}
}
}
class Name {
public $x = 1;
public function metod() {
return 2;
}
}
$object = new Object(new Name());
echo $object->x;
echo $object->metod();