i think you should array_swap and then check with isset instead of in_array. in_array needs to loop through the whole array for each lookup - once swapped the values are the keys and isset is a fast hash lookup.