3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $actualArray = array( user1 => array( 'name' => 'User1', 'age' => '25', 'lastLogin' => '2013-08-16' ), user1 => array( 'name' => 'User1', 'age' => '25', 'lastLogin' => '2013-08-10' ), user2 => array( 'name' => 'User2', 'age' => '35', 'lastLogin' => '2013-08-08' ), user1 => array( 'name' => 'User1', 'age' => '25', 'lastLogin' => '2013-07-10' ) ); function uniqueAssocArray($array, $uniqueKey) { if (!is_array($array)) { return array(); } $uniqueKeys = array(); foreach ($array as $key => $item) { if (!in_array($item[$uniqueKey], $uniqueKeys)) { $uniqueKeys[$item[$uniqueKey]] = $item; } } return $uniqueKeys; } print_r(uniqueAssocArray($actualArray, 'name'));
Output for 7.2.0 - 7.2.8
Warning: Use of undefined constant user1 - assumed 'user1' (this will throw an Error in a future version of PHP) in /in/I7U2u on line 3 Warning: Use of undefined constant user1 - assumed 'user1' (this will throw an Error in a future version of PHP) in /in/I7U2u on line 8 Warning: Use of undefined constant user2 - assumed 'user2' (this will throw an Error in a future version of PHP) in /in/I7U2u on line 13 Warning: Use of undefined constant user1 - assumed 'user1' (this will throw an Error in a future version of PHP) in /in/I7U2u on line 18 Array ( [User1] => Array ( [name] => User1 [age] => 25 [lastLogin] => 2013-07-10 ) [User2] => Array ( [name] => User2 [age] => 35 [lastLogin] => 2013-08-08 ) )
Output for 5.5.0 - 7.1.20
Notice: Use of undefined constant user1 - assumed 'user1' in /in/I7U2u on line 3 Notice: Use of undefined constant user1 - assumed 'user1' in /in/I7U2u on line 8 Notice: Use of undefined constant user2 - assumed 'user2' in /in/I7U2u on line 13 Notice: Use of undefined constant user1 - assumed 'user1' in /in/I7U2u on line 18 Array ( [User1] => Array ( [name] => User1 [age] => 25 [lastLogin] => 2013-07-10 ) [User2] => Array ( [name] => User2 [age] => 35 [lastLogin] => 2013-08-08 ) )
Output for 4.3.0 - 5.4.45
Array ( [User1] => Array ( [name] => User1 [age] => 25 [lastLogin] => 2013-07-10 ) [User2] => Array ( [name] => User2 [age] => 35 [lastLogin] => 2013-08-08 ) )