3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $database=array(array("Test 1","021"),array("Test 2","033"),array("Test 3","022"),array("Test 3","022"),array("Test 3","033"),array("Test 2","022"),array("Test 2","021")); $source=array(); foreach($database as $row) { $source[]=json_encode(array("message"=>$row[0],"number"=>$row[1])); } print_r($source); $unique=array_map(function($str){ return json_decode($str,true); },array_unique($source)); print_r($unique);
Output for 5.3.0 - 7.1.0
Array ( [0] => {"message":"Test 1","number":"021"} [1] => {"message":"Test 2","number":"033"} [2] => {"message":"Test 3","number":"022"} [3] => {"message":"Test 3","number":"022"} [4] => {"message":"Test 3","number":"033"} [5] => {"message":"Test 2","number":"022"} [6] => {"message":"Test 2","number":"021"} ) Array ( [0] => Array ( [message] => Test 1 [number] => 021 ) [1] => Array ( [message] => Test 2 [number] => 033 ) [2] => Array ( [message] => Test 3 [number] => 022 ) [4] => Array ( [message] => Test 3 [number] => 033 ) [5] => Array ( [message] => Test 2 [number] => 022 ) [6] => Array ( [message] => Test 2 [number] => 021 ) )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/VAuUo on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/VAuUo on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/VAuUo on line 9
Process exited with code 255.