3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
array(3) { [0]=> array(6) { ["action"]=> string(5) "Added" ["amount"]=> string(1) "1" ["code"]=> string(4) "RNA1" ["name"]=> string(20) "Mens Organic T-shirt" ["colour"]=> string(5) "White" ["size"]=> string(2) "XL" } [1]=> array(6) { ["action"]=> string(10) "Subtracted" ["amount"]=> string(1) "7" ["code"]=> string(4) "RNC1" ["name"]=> string(18) "Kids Basic T-shirt" ["colour"]=> string(10) "Denim Blue" ["size"]=> string(4) "3-4y" } [2]=> array(6) { ["action"]=> string(5) "Added" ["amount"]=> string(2) "20" ["code"]=> string(4) "RNV1" ["name"]=> string(12) "Gift Voucher" ["style"]=> string(4) "Mens" ["value"]=> string(4) "£20" } }

preferences:
76.43 ms | 409 KiB | 5 Q