Home » Tricks » group by in array PHP

Summary: Hi, everyone. In this post I am going to show you how we can group by in array PHP by using foreach loop. We have no defalut function for groupby of array in php. Let’s start, We have a array which contain Items in key and It’s owner in value.

But we need to show result like below:

Let’s do it. First of all, I take an empty array named $newArray. Take array in a variable
$group apply foreach loop. As I show below:

 

In result, we got what we want. You can try here(link ) with the live demo.

That’s all! 🙂
Still, face any problem you can post your comment below we definitely help you 🙂

all git commands for the beginner

Back to top