3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_words = ['harmony', 'Acrobat', 'harmony', 'harmony']; $array_words_unique = array_unique($array_words); //get a list of unique words from the original array $array_str = implode(",", $array_words); foreach ($array_words_unique as $word) { //count how many times the word occurs $count = substr_count($array_str, $word); //if it occurs more than once, remove the first occurence if ($count > 1) { //find the first position of the word in the string, then replace that with nothing $pos = strpos($array_str, $word); $array_str = substr_replace($array_str, "", $pos, strlen($word)); } } //convert back to an array, and filter any blank entries caused by commas with nothing between them $array_final = array_filter(explode(",", $array_str)); var_dump($array_final);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { [1]=> string(7) "Acrobat" [2]=> string(7) "harmony" [3]=> string(7) "harmony" }

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.56 ms | 405 KiB | 5 Q