$product = Mage::getModel('catalog/product')->load(123); // Load product with ID 123 $categoryIds = [5, 7, 10]; // Array of category IDs to assign to product $product->setCategoryId($categoryIds); // Assign categories to product $product->save(); // Save changes to databaseIn this example, we load a product with an ID of 123 and assign it to three categories with IDs of 5, 7, and 10. The package library for this code example is Magento Core.