I have created a custom module and I have return collection array but it does not return foreach array in Magento 2.3.2. it returns the only foreach last value.
Block Code
<?php
namespace Developer\Infographics\Block\Index;
use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\CategoryFactory;
class Leftinfographics extends Template {
public function __construct(
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
array $data = [])
{
parent::__construct($context, $data);
$this->pageConfig = $pageConfig;
$this->collectionFactory = $collectionFactory;
}
public function getCategoryViceversaCollection()
{
$collection = array();
$finalsearch = 'test,magento,abc,xyz'
$commaList = explode(',', $finalsearch);
foreach ($commaList as $key => $value) {
$collection = $this->collectionFactory->create()->getCollection()->addFieldToFilter('tags', array('like' => '%'.$value.'%'));
}
return $collection;
}
}
Template Code
$productxyzdata = $block->getXYZ();
var_dump($productCollectiondata->getData());