We have to show the first element of the array to the last Check below code
public function getFilters(MagentoCatalogModelLayer $layer)
{
if (!count($this->filters)) {
$this->filters = [
$this->objectManager->create(
$this->filterTypes[self::CATEGORY_FILTER],
['layer' => $layer]
),
];
foreach ($this->filterableAttributes->getList() as $attribute) {
$this->filters[] = $this->createAttributeFilter($attribute, $layer);
}
}
return $this->filters;
}
The result of $this->filters will look like
$this->filters[0] = MagentoCatalogSearchModelLayerFilterCategory
$this->filters[1] = MagentoCatalogSearchModelLayerFilterAttribute
$this->filters[2] = MagentoCatalogSearchModelLayerFilterAttribute
$this->filters[3] = MagentoCatalogSearchModelLayerFilterAttribute
$this->filters[4] = MagentoCatalogSearchModelLayerFilterAttribute
How to move it?
2
Answers
You can use array_shift() for this:
Sample output:- https://3v4l.org/WULpM
It depends, do you want to swap the first and last element, or would you want to remove the element from the end of the array and prepend it to the beginning (effectively having moved all elements on further).
For the former, you could use (as mentioned at Swap array values with php)
For the latter you could use: