XF 2.2 Fastest way to find a value in an array

Robert9

Well-known member
I have an array of categories (around 2000)
I want to unset just one value in this array.

I can do now:

1.
Code:
foreach($categories AS $key => $value)
{
    if $value == 1
    unset $categories[$key]
}

2.
Because all indexes are unique and all category_ids are unique i could do:
$flippedCategories = array_flip($categories);
unset($flippedCategories[1]);
$categories = array_flip($flippedCategories);

3.
Maybe it is a better way to extend the repository from
Code:
$resourceFinder
            ->with(['full', 'fullCategory'])
            ->useDefaultOrder();

to

Code:
$resourceFinder
            ->with(['full', 'fullCategory'])
            ->where('category_id != "1")
            ->useDefaultOrder();

I guess that 3. is much better than 1 or 2,
and 2 is better than 1?
 
Back
Top Bottom