I currently have an array of three strings, and my goal is to turn these three strings from the array into individual associative arrays.
This is the array:
$arr = array(
"action: Added; amount: 1; code: RNA1; name: Mens Organic T-shirt; colour: White; size: XL",
"action: Subtracted; amount: 7; code: RNC1; name: Kids Basic T-shirt; colour: Denim Blue; size: 3-4y",
"action: Added; amount: 20; code: RNV1; name: Gift Voucher; style: Mens; value: £20",
I'd like to have the key of the associative array be the action, quantity, item code etc and to start off I thought I should try turning the contents of the array into a string to make it more manageable.
// Convert $arr to a string.
$imploded = implode(": ",$arr);
//echo $imploaded;
$str = $imploded;
$results = preg_split('/: [;,]/', $str);
print_r($results);
Ideally, i'd like the array to look like this. I'm quite new to PHP so any help and advice would be much appreciated.
array(
'action' => '',
'amount' => '',
'code' => '',
'name' => '',
'colour' => '',
'size' => '',
);