Currently, I have a 2d array, which is basiccaly like this:
$oriArr = array(
[0]=>array(
'1'=>'a',
'2'=>'b',
'3-1'=>'c',
'4-1'=>'d',
'3-2'=>'c1',
'4-2'=>'d1'
),
[1]=>array(
'1'=>'a',
'2'=>'b',
'3-1'=>'c',
'4-1'=>'d',
'3-2'=>'c1',
'4-2'=>'d1',
'3-3'=>'c2',
'4-3'=>'d2'
),
);
I want to split the array into 3d array by adding a new element like this:
$resArr= array(
[0]=>array(
[1]=>'a',
[2]=>'b',
['items']=>array(
[1]=>array(
'3-'=>'c',
'4-'=>'d',
),
[2]=>array(
'3-'=>'c1',
'4-'=>'d1',
)
),
),
[0]=>array(
[1]=>'a',
[2]=>'b',
['items']=>array(
[1]=>array(
'3-'=>'c',
'4-'=>'d',
),
[2]=>array(
'3-'=>'c1',
'4-'=>'d1',
),
[3]=>array(
'3-'=>'c2',
'4-'=>'d2',
)
),
),
);
I tried to split all the keys with '-' and add them to another array, but I dont know how to add a new element called 'items' and insert the values into it.
foreach($oriArr as $lines){
foreach($lines as $keys){
$keyArr= array();
if (strpos($keys, '-') !== false) {
$keyArr[] = $keys;
}
}
}
Is there any way that I can split my original array? Any answer would be appreciated!