Strip all elements from array where they occur less than twice

I have an array like this:

[0] = 2
[1] = 8
[2] = 7
[3] = 7

And I want to end up with an array that looks like:

[0] = 7
[1] = 7

Basically, remove all elements where they occur less than twice.

Is their a PHP function that can do this?

Answers


try this,

$ar1=array(2,3,4,7,7);
    $ar2=array();
    foreach (array_count_values($ar1) as $k => $v) {
        if ($v > 1) {
            for($i=0;$i<$v;$i++)
            {
            $ar2[] = $k;
            }
        }
    }
    print_r($ar2);

output

Array ( [0] => 7 [1] => 7 )


Need Your Help

XMLHttpRequest responseText not including all the XML

javascript ajax xml

I am new to XML and have been doing some of the tutorials on the w3schools website.

Locomotive wagon does not display data in local development site

locomotivecms wagon

I have an existing locomotive site that I am setting up for development on my machine. The engine is running locally and I am using the wagon gem to edit the theme files.