in reply to making code efficient

I am not able to understand your code. The $error has no value as $cro_max = 0 and therefore it is giving uninitialized value for error. Also r1 is not used after it has been initialized and two of your values $rL3 and $OR1 values are not initialized or defined.Please briefly state what are doing and what you want to do ?