I've got an multidimensional array with some values.
[
1 => [
'label' => 'SEO',
'content' => 'Some content',
'group' => 'We can offer'
]
2 => [
'label' => 'Webdesign',
'content' => 'Some content',
'group' => 'We can offer'
]
3 => [
'label' => 'Contact',
'content' => 'Some content',
'group' => 'Who are we?'
]
4 => [
'label' => 'Logodesign',
'content' => 'Some content',
'group' => 'We can offer'
]
5 => [
'label' => 'Address',
'content' => 'Some content',
'group' => 'Who are we?'
]
]
The group element is a variety of user input. I want to sort all group elements what are the same into the same array. It's then going to be displayed. If there are only 2 elements with the same group value, then there will only be two columns (50% width on both) in a .row element in HTML, if there are 1 element, only one column (100% width). I'm trying to build a very simple CMS if anyone was wondering why. There may be more easier ways to do this, but I can't think of any.
Any help is appreciated.
EDIT:
I just got the array sorted i think. It looks right.
Now I just need to display it the right way.
$i = 0;
$count = count($data['sections']);
$content = [];
for ($i = 0; $i < $count; $i++) {
if (!in_array($data['sections'][$i]['group'], $content)) {
$content[] = $data['sections'][$i]['group'];
}
$content[$data['sections'][$i]['group']][] = ['label' => $data['sections'][$i]['label'], 'content' => $data['sections'][$i]['content']];
}
.c-#-12