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 git.master, git.master_jit, rfc.property-hooks
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" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
57 ms | 407 KiB | 5 Q