PHP 8.4.24 Released!

Voting

: max(nine, two)?
(Example: nine)

The Note You're Voting On

Victoire Nkolo at crinastudio.com
3 years ago
<?php

//removes duplicated objetcs from an array according to the property given

class ArrayFilter
{

    public static function dedupe_array_of_objets(array $array, string $property) : array
    {
        $i = 0;
        $filteredArray = array();
        $keyArray = array();

        foreach($array as $item) {
            if (!in_array($item->$property, $keyArray)) {
                $keyArray[$i] = $item->$property;
                $filteredArray[$i] = $item;
            }
            $i++;
        }
        return $filteredArray;
    }
}

<< Back to user notes page

To Top