- array_map: documentation ( source)
- array_combine: documentation ( source)
- array_chunk: documentation ( source)
- print_r: documentation ( source)
- preg_split: documentation ( source)
<?php
$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",
);
$result = array_map(function($line) {
return array_combine(...array_map(null, ...array_chunk(preg_split('/[:;]\s+/', $line), 2)));
}, $arr);
print_r($result);