I am having an issue splitting a multidimensional array into sub-arrays based on repeating values. Here is the issue-
Current array:
Array (
[2] => first=1
[3] => second=2
[4] => third=
[5] => first=4
[9] => second=3
...
);
Intended result:
Array(
[0] =>
Array(
[first] => 1,
[second] => 2,
[third] =>
...
),
[1] =>
Array(
[first] => 4,
[second] => 3
...
),
);
Trying to achieve by manipulating it like this but stuck this far-
$filtered_array_splitted = [];
$array_tracker = 0;
$array_tracker_in = 0;
foreach ($filtered_array as $key => $value) {
parse_str(str_replace('', '=', $value), $mapped_value_as_pair);
$filtered_array_splitted[$array_tracker++] = array_merge($mapped_value_as_pair);
}
print_r($filtered_array_splitted);
This just split them into sub-arrays, I need to insert them based on duplication occurrence. Anytime same key is found, new sub-array will be formed.