3v4l.org

run code in 300+ PHP versions simultaneously
<?php class my_obj { public $term_id; public $name; public $slug; public function __construct($i, $n, $s) { $this->term_id = $i; $this->name = $n; $this->slug = $s; } } $objA = new my_obj(23, "Assasination", "assasination"); $objB = new my_obj(14, "Campaign Finance", "campaign-finance"); $objC = new my_obj(15, "Campaign Finance", "campaign-finance-good-government-political-reform"); $array = array($objA, $objB, $objC); echo "Original array:\n"; print_r($array); /** Answer Code begins here */ $filtered = array_intersect_key($array, array_unique(array_column($array, 'name'))); /** Answer Code ends here */ echo "After removing duplicates\n"; print_r($filtered);
Output for git.master, git.master_jit, rfc.property-hooks
Original array: Array ( [0] => my_obj Object ( [term_id] => 23 [name] => Assasination [slug] => assasination ) [1] => my_obj Object ( [term_id] => 14 [name] => Campaign Finance [slug] => campaign-finance ) [2] => my_obj Object ( [term_id] => 15 [name] => Campaign Finance [slug] => campaign-finance-good-government-political-reform ) ) After removing duplicates Array ( [0] => my_obj Object ( [term_id] => 23 [name] => Assasination [slug] => assasination ) [1] => my_obj Object ( [term_id] => 14 [name] => Campaign Finance [slug] => campaign-finance ) )

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:
70.41 ms | 407 KiB | 5 Q