Improve efficiency of required_if_not

Why call array_get for every loop iteration when neither the array nor index is changing? It will give the same value each time so it's better to store it and use the stored result.