Please help me to solve one problem that I am really stuck in PHP
I have one big array
$a = array(
'foo_1' => 'Dog',
'bar_1' => 'Cat',
'baz_1' => 'Fish',
'foo_2' => 'Frog',
'bar_2' => 'Bug',
'baz_2' => 'Ddd',
...
);
and it needs to be transformed in multiple arrays:
$a_1 = array(
'foo' => 'Dog',
'bar' => 'Cat',
'baz' => 'Fish'
);
$a_2 = array(
'foo' => 'Frog',
'bar' => 'Bug',
'baz' => 'Ddd'
);
As you noticed there is a small logic. The big array should be splited by sets of keys ( _1,_2,_3 ; _1,_2,_33 )
Hope I was clear enough!
Thanks
Assuming
$ahas this structure (because OP original array has duplicate keys):You can transform array by this approach: