3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "one" => ["id" => 111, "name" => "Jhon"], "two" => ["id" => 222, "name" => "Adam"], "three" => ["id" => 111, "name" => "Mark"], "four" => ["id" => 125, "name" => "Jhon"], "five" => ["id" => 111, "name" => "Jhon"], "six" => ["id" => 222, "name" => "Rock"], ]; // store added IDs $added = []; // filter array (need to pass $added as reference to be updated) $output = array_filter($array, function($item) use (&$added) { // shortcut for readability $id = $item['id']; // Check if id already exists if (isset($added[$id])) { return false; } // add to reference $added[$id] = true; // add to final array return true; }); unset($added); // no longer needed. var_dump($output);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { ["one"]=> array(2) { ["id"]=> int(111) ["name"]=> string(4) "Jhon" } ["two"]=> array(2) { ["id"]=> int(222) ["name"]=> string(4) "Adam" } ["four"]=> array(2) { ["id"]=> int(125) ["name"]=> string(4) "Jhon" } }

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:
103.55 ms | 406 KiB | 5 Q