3v4l.org

run code in 300+ PHP versions simultaneously
<?php $source=json_decode('[{"title":"games","transaction_id":102,"order_id":"a"},{"title":"media","transaction_id":95,"order_id":"b"},{"title":"tv","transaction_id":102,"order_id":"a"},{"title":"jane","transaction_id":42,"order_id":"a"},{"title":"ads","transaction_id":95,"order_id":"b"},{"title":"movie","transaction_id":95,"order_id":"c"}]',true); function merge(array $source) { $result=array(); foreach($source as $node) { $key=$node["transaction_id"]."_".$node["order_id"]; if(!empty($result[$key])) $result[$key][]=$node["title"]; else $result[$key]=array($node["title"]); } return array_values($result); } print_r($source);//Just for debug print_r(merge($source));
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Array ( [0] => Array ( [title] => games [transaction_id] => 102 [order_id] => a ) [1] => Array ( [title] => media [transaction_id] => 95 [order_id] => b ) [2] => Array ( [title] => tv [transaction_id] => 102 [order_id] => a ) [3] => Array ( [title] => jane [transaction_id] => 42 [order_id] => a ) [4] => Array ( [title] => ads [transaction_id] => 95 [order_id] => b ) [5] => Array ( [title] => movie [transaction_id] => 95 [order_id] => c ) ) Array ( [0] => Array ( [0] => games [1] => tv ) [1] => Array ( [0] => media [1] => ads ) [2] => Array ( [0] => jane ) [3] => Array ( [0] => movie ) )
Output for 5.1.0 - 5.1.6
Fatal error: Call to undefined function json_decode() in /in/e3ERO on line 2
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/e3ERO on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/e3ERO on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/e3ERO on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/e3ERO on line 3
Process exited with code 255.

preferences:
255.14 ms | 401 KiB | 386 Q