<?php
$arr = [
"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",
];
$keyed = array_reduce($arr, function($collector, $value) {
$collector[] = array_reduce(explode('; ', trim($value, '; ')), function($collector, $value) {
$parts = explode(': ', $value);
$collector[$parts[0]] = $parts[1];
return $collector;
}, []);
return $collector;
}, []);
var_dump($keyed);
preferences:
33.94 ms | 407 KiB | 5 Q