How to alter the options inside element of a civicrm new membership form?
I'd do it like this: 


First get the name of the select element, and then get the elemement using this 


$element =&amp; $form->getElement('name-of-select-element');

i.e. don't hard code that 4.


You've got the options array correct, i.e. $element->_options


Now you can just replace that options like you're doing, but depending on the widget in use it can be confusing how it's structured. The one I was working on recently has option['text'] as the label. Sorting by array values can be done manually or cleverly with some php and callback functions if you're ambitious.