Drupal 7 : Select list options by Taxonomy term depth(Parent Child) with source code

In Drupal by Taxonomy term list are arranged as parent child format. Similarly we can able to create List option in our custom form. Below is the source code to generate option array as Parent child hierarchy. List key is Term ID and display name is Taxonomy term hierarchy.