Urgent request: java interface is written in php syntax

Code:
Set < SearchFieldsEnum > searchFields = new HashSet < SearchFieldsEnum >
();
searchFields.add (SearchFieldsEnum.USER_ID);

question: how to implement this code with php?

Apr.15,2021

Set is not supported in

php, so you can consider using array to implement

.
<?php

Class Set {
    private $arr = [];
    public function add($val) {
        if (!in_array($val, $this->arr)) {
            array_push($this->arr, $val);
        }
        return $this->arr;
    }
}

$set = new Set();
print_r($set->add(2));
print_r($set->add(2));
print_r($set->add(3));
print_r($set->add(4));

the ability is limited, if there is a mistake, please do not hesitate to give advice.

Menu