use Zend\ServiceManager\ServiceLocatorInterface;
/**
* ServiceManagerAwareTrait trait.
*/
trait ServiceManagerAwareTrait
{
/**
* $serviceManager instance.
* @var ServiceLocatorInterface
*/
protected $serviceManager = null;
/**
* Set $serviceManager.
*
* @param ServiceLocatorInterface $serviceManager
* @return self
*/
public function setServiceManager(ServiceLocatorInterface $serviceManager)
{
$this->serviceManager = $serviceManager;
return $this;
}
/**
* Retrieve $serviceManager.
*
* @return ServiceLocatorInterface $serviceManager
*/
public function getServiceManager()
{
return $this->serviceManager;
}
}
$array = [
[
'id' => '100', //допустим, id
'name' => 'Фрукты', //Название
'sub_category' => [
'id' => '101',
'name' => 'Цитрусовые',
'product' => [
[
'id' => '102',
'name' => 'Апельсин'
],
[
'id' => '103',
'name' => 'Мандарин',
]
]
]
],
[
'id' => '103',
'name' => 'Овощи',
'sub_category' => [
'id' => '104',
'name' => 'Корнеплоды',
'product' => [
[
'id' => '105',
'name' => 'Картофель'
],
[
'id' => '106',
'name' => 'Морковь',
]
]
]
],
];
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));
$names = [];
foreach ($iterator as $name) {
$depth = floor($iterator->getDepth()/2);
$names[$depth] = $name;
echo implode(' > ', array_slice($names, 0, $depth + 1)), '<br>', PHP_EOL;
}
<?php $caritem = ["car__item_left", "car__item_left-bottom", "car__item_middle", "car__item_middle-bottom"]; ?>
<div class="car__items">
<?php foreach($caritem as $key1 => $value): ?>
<?php foreach ($arResult['ITEMS'] as $key2 => $arItem): ?>
<div class="<?= 'car__item' . $value ?>">
<div class="car__button"></div>
<div class="car__hover car__hover_mobile">
<h3 class="car__title"><?= $arItem['NAME'] ?></h3>
<div class="car__text">
<p><?= $arItem['PREVIEW_TEXT'] ?></p>
</div>
<a class="link link_car" href="<?= $arItem['DETAIL_PAGE_URL']?>">Подробнее</a>
</div>
</div>
<?php endforeach ?>
<?php endforeach ?>
</div>
/**
* Включаем автозагрузку классов в PHP с использованием SPL.
*/
spl_autoload_extensions('.php');
spl_autoload_register();
array_walk($guide['postInGuides'], function (&$postInGuide, $key) use ($guide, $viewRenderer) {
$postInGuide['post']['url'] = [
'read' => $viewRenderer->url('guide/guide/post', [
'slugGuide' => $guide['name'],
'slugPost' => $postInGuide['post']['slug'],
]),
'update' => $viewRenderer->url('post/post/action', [
'slugPost' => $postInGuide['post']['slug'],
'action' => 'update',
]),
'delete' => $viewRenderer->url('post/post/action', [
'slugPost' => $postInGuide['post']['slug'],
'action' => 'delete',
]),
];
});