I have 2 arrays.
Array of goods and array of separators.
$goods = [
[
'good_id' => '1',
'name' => 'Good 1',
],
[
'good_id' => '24',
'name' => 'Good 24',
],
[
'good_id' => '335',
'name' => 'Good 335',
],
[
'good_id' => '1986',
'name' => 'Good 1986',
],
];
$separators = [
[
'id' => '1',
'good_id' => '0',
'name' => 'Separator 1',
],
[
'id' => '2',
'good_id' => '0',
'name' => 'Separator 2',
],
[
'id' => '3',
'good_id' => '4',
'name' => 'This separator should set after 4 good_id and before 5 good_id if exists',
],
[
'id' => '4',
'good_id' => '47',
'name' => 'This separator should set after 47 good_id and before 48 good_id if exists',
],
[
'id' => '5',
'good_id' => '9999',
'name' => 'This separator should set after 9999 good_id and before 10000 good_id if exists',
],
[
'id' => '6',
'good_id' => '9999',
'name' => 'This separator should set after 9999 good_id and AFTER prevously separator AND before 10000 good_id if exists',
]
];
I need to merge this arrays by good_id.
Spearators good_id should sets after goods good_id by good_id.
$merged = [
[
'id' => '1',
'good_id' => '0',
'name' => 'Separator 1',
],
[
'id' => '2',
'good_id' => '0',
'name' => 'Separator 2',
],
[
'good_id' => '1',
'name' => 'Good 1',
],
[
'id' => '3',
'good_id' => '4',
'name' => 'This separator should set after 4 good_id and before 5 good_id if exists',
],
[
'good_id' => '24',
'name' => 'Good 24',
],
[
'id' => '4',
'good_id' => '47',
'name' => 'This separator should set after 47 good_id and before 48 good_id if exists',
],
[
'good_id' => '335',
'name' => 'Good 335',
],
[
'good_id' => '1986',
'name' => 'Good 1986',
],
[
'id' => '5',
'good_id' => '9999',
'name' => 'This separator should set after 9999 good_id and before 10000 good_id if exists',
],
[
'id' => '6',
'good_id' => '9999',
'name' => 'This separator should set after 9999 good_id and AFTER prevously separator AND before 10000 good_id if exists',
]
];