3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
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.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.