3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr = array( array('status'=>'OK','Productname'=>'test1'), array('status'=>'OK','Productname'=>'test1'), array('status'=>'OK','Productname'=>'test2'), array('status'=>'OK','Productname'=>'test2') ); $notToDuplicate = array('test2'); $newArray = array_unique($arr, SORT_REGULAR); foreach($arr as $key => &$val) { if(!in_array($val['Productname'],$arr)) { foreach($newArray as $v) { if($v !== $val) { $newArray[] = $val; } } } } print_r($newArray);
Output for 5.4.34 - 7.1.0
Array ( [0] => Array ( [status] => OK [Productname] => test1 ) [2] => Array ( [status] => OK [Productname] => test2 ) [4] => Array ( [status] => OK [Productname] => test1 ) [5] => Array ( [status] => OK [Productname] => test1 ) [6] => Array ( [status] => OK [Productname] => test2 ) [7] => Array ( [status] => OK [Productname] => test2 ) [8] => Array ( [status] => OK [Productname] => test2 ) [9] => Array ( [status] => OK [Productname] => test2 ) [10] => Array ( [status] => OK [Productname] => test2 ) [11] => Array ( [status] => OK [Productname] => test2 ) )
Output for 5.2.9 - 5.4.32
Array ( [0] => Array ( [status] => OK [Productname] => test1 ) [2] => Array ( [status] => OK [Productname] => test2 ) [3] => Array ( [status] => OK [Productname] => test1 ) [4] => Array ( [status] => OK [Productname] => test1 ) [5] => Array ( [status] => OK [Productname] => test2 ) [6] => Array ( [status] => OK [Productname] => test2 ) [7] => Array ( [status] => OK [Productname] => test2 ) [8] => Array ( [status] => OK [Productname] => test2 ) [9] => Array ( [status] => OK [Productname] => test2 ) [10] => Array ( [status] => OK [Productname] => test2 ) )
Output for 5.0.0 - 5.2.8
Warning: Wrong parameter count for array_unique() in /in/Ihj9v on line 11 Warning: Invalid argument supplied for foreach() in /in/Ihj9v on line 15 Warning: Invalid argument supplied for foreach() in /in/Ihj9v on line 15 Warning: Invalid argument supplied for foreach() in /in/Ihj9v on line 15 Warning: Invalid argument supplied for foreach() in /in/Ihj9v on line 15
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/Ihj9v on line 13
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/Ihj9v on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/Ihj9v on line 13
Process exited with code 255.