I have an array that comes from a form POST and I'd like to group these together.
My first attempt is running a foreach loop on the array, but I'm unsuccesful in getting the logic to group them. I have the idea of creating a dynamic array using the number from the keys, but I'm unable to grab that number.
Initial array:
["affix-1-order"]=> "1";
["affix-1-type"]=> "Apple";
["affix-1-count"]=> "5";
["affix-3-order"]=> "2";
["affix-3-type"]=> "Orange";
["affix-3-count"]=> "10";
["affix-2-order"]=> "3";
["affix-2-type"]=> "Banana";
["affix-2-count"]=> "3";
["affix-4-order"]=> "4";
["affix-4-type"]=> "Mango";
["affix-4-count"]=> "15";
Expected output:
["1"]=> [{
["type"]=> "Apple",
["count"]=> "5",
["order"]=> "1"
}],
["2"]=> [{
["type"]=> "Banana",
["order"]=> "3",
["count"]=> "3"
}],
["3"]=> [{
["type"]=> "Orange",
["order"]=> "2",
["count"]=> "10",
}],
["4"]=> [{
["type"]=> "Mango",
["order"]=> "4",
["count"]=> "15"
}];
name=X[]['type']name=X[]['order']name=X[]['count'], the post X array will be what you want