I am in the situation where I want to group the arrays in PHP to group on the base of there group ID, What I am getting is the following
Array (
[0] => Array (
[raw] => I am text string
[group_id] => 1
)
[1] => Array (
[raw] => Another text string
[group_id] => 1
)
[2] => Array (
[raw] => text placeholder
[group_id] => 2
)
)
but I want the output like below
Array (
[0] => Array (
Array(
[0] => Array (
[raw] => I am text string
[group_id] => 1
)
[1] => Array (
[raw] => Another text string
[group_id] => 1
)
)
[1] => Array (
[raw] => text placeholder
[group_id] => 2
)
)
In the current output, You can notice that 'group_id' of the first two array elements are the same i.e. 1, and in the expected output the elements with the same 'group_id' are wrapped into a parent array.
for your consideration, here is the array code;
<?php
$output = array(
array ("raw"=> "I am text string", "group_id" => 1),
array ("raw"=> "Another text string", "group_id" => 1),
array ("raw"=> "text placeholder", "group_id" => 2),
);
print_r($output);
?>
So ultimately, I want to group the arrays with same 'group_id' into another array.
Thank you in advance for your time and help.
any help is appreciated as I am not getting the logic.