Get Top Level Categories Only

<?php // remove opening php tag
// make sure we're only pulling top level categories
$categories = get_the_category();
$top_level_cat_obj = array();
foreach( $categories as $cat ) {
     if( $cat->parent == 0 ) {
          $top_level_cat_obj[] = $cat;
     }
}
// get first item from array
$top_level_cat_obj = $top_level_cat_obj[0];