add a "break;" before exiting the if block.  There is no need to continue iterating after finding $pref