3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Remove duplicate elements from an array using a user-defined Reductor function. * @param array $array * @param callable $reductor Reduces a single array element to a simple type for equivalence checking. */ function array_uunique(array $array, callable $reductor) { $seen = []; return array_filter( $array, function($a)use(&$seen, $reductor){ $val = $reductor($a); if( ! in_array($val, $seen, true) ) { $seen[] = $val; return true; } else { return false; } } ); } $arr = [ [ 'target' => 'a' ], [ 'target' => 'b' ], [ 'target' => 'c' ], [ 'target' => 'd' ], [ 'target' => 'c' ], [ 'target' => 'e' ], ]; echo json_encode( array_uunique($arr, function($a){return $a['target'];}), JSON_PRETTY_PRINT ) . PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
{ "0": { "target": "a" }, "1": { "target": "b" }, "2": { "target": "c" }, "3": { "target": "d" }, "5": { "target": "e" } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.39 ms | 401 KiB | 8 Q