Fetch the categories associated with the products on listing page magento

<?php
$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $product):
foreach($product->getCategoryIds() as $category):
$categoryIds[] = $category;
endforeach;
endforeach;

print_r( $categoryIds );

?>