I created a site by laravel and I want to show categories and relevant products names.
I have an array and like this
$category = [
'1' => 'cat1',
'2' => 'cat2'
];
$product = [
'0' => array(
'name' => 'product1',
'category_id' => '2'
),
'1' => array(
'name' => 'product2',
'category_id' => '2'
),
'2' => array(
'name' => 'product3',
'category_id' => '2'
),
'3' => array(
'name' => 'product4',
'category_id' => '1'
),
'4' => array(
'name' => 'product5',
'category_id' => '1'
),
'5' => array(
'name' => 'product6',
'category_id' => '2'
)];
and I want to showing it like this
<h3>cat1</h3>
<p>product4</p>
<p>product5</p>
<hr>
<hr>
<h3>cat2</h3>
<p>product1</p>
<p>product2</p>
<p>product3</p>
<p>product6</p>
You have to know I'm using laravel and I want doing this job with laravel but you also can coding with PHP, I think I can to convert it in laravel
$categoryand within that loop, another loop with$product.