Find a better way to manage the PHP bug on array_search