I have built a program that takes data from an array full of strings, and turns the data into an appropriately formatted array. This is the original array:
$arr = array(
"action: Added; quantity: 1; item_code: RNA1; product_name: Mens Organic T-shirt; colour: White; size: XL",
"action: Subtracted; quantity: 7; item_code: RNC1; product_name: Kids Basic T-shirt; colour: Denim Blue; size: 3-4y",
"action: Added; quantity: 20; item_code: RNV1; product_name: Gift Voucher; style: Mens; value: £20",
);
And this is the new array with the data appropriately formatted.
Array
(
[0] => Array
(
[0] => action: Added
[1] => quantity: 1
[2] => item_code: RNA1
[3] => product_name: Mens Organic T-shirt
[4] => colour: White
[5] => size: XL
)
[1] => Array
(
[6] => action: Subtracted
[7] => quantity: 7
[8] => item_code: RNC1
[9] => product_name: Kids Basic T-shirt
[10] => colour: Denim Blue
[11] => size: 3-4y
)
[2] => Array
(
[12] => action: Added
[13] => quantity: 20
[14] => item_code: RNV1
[15] => product_name: Gift Voucher
[16] => style: Mens
[17] => value: £20
)
)
Here, I thought I should change the array into an associative key-value pair array, and thought that it would be relatively simple if I could find a way to convert the array into said associative array by splitting it by a character, in this case ":".
In the end, i'd like the array to look like:
'action' => '',
'quantity' => '',
'item_code' => '',
'product_name' => '',
...Etc.
I have tried using the array_column and the array_combine functions, but I haven't had much luck where i'm relatively new to PHP. Any help is greatly appreciated!