Home    Articles


How to get all categories from magento as array list


In order to get all categories from magento as array, not as object use the following code.

The following code will get the categories ids from magento, will load each category, an array with data about each category will be builded and the function will return the results.

function getAllCategories()
	$category = Mage::getModel('catalog/category'); 
	$treeModel = $category->getTreeModel(); 
	$ids = $treeModel->getCollection()->getAllIds(); 
	$data = array();
	if (!empty($ids))
		foreach ($ids as $id)
			$cat = Mage::getModel('catalog/category'); 
			$categoryData = array('id'=>$cat->getId(),
			array_push($data, $categoryData); 
	return $data;
$categories = getAllCategories();
echo '<pre/>';print_r($categories);exit;

In order to get some other data about some category change the function by addind data in array.

That’s all.