PHPize Online / SQLize Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy
Copy Format Clear
<?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" ); $res = array_reduce( $arr, function($acc, $item) { $s = array_reduce( explode(';', $item), function($a, $el) { $p = explode(': ', $el); $a[trim($p[0])] = trim($p[1]); return $a; }, [] ); array_push($acc, $s); return $acc; }, [] ); print_r($res);
Show:  
Copy