Your function displayStateSelect('state', null) actually writes the <select> element to the output buffer via an echo or other method instead of using a return which would allow you to use your first method.