What is the purpose of using Composer in PHP projects?

When working on PHP projects, managing dependencies manually can be time-consuming and error-prone. Composer is a dependency management tool for PHP that simplifies the process of installing and updating libraries or packages required for a project. By using Composer, developers can easily declare the dependencies their project needs and let Composer handle the rest, ensuring that the required libraries are installed correctly.

// Example of using Composer to install a package
// Step 1: Install Composer globally on your system
// Step 2: Create a new PHP project directory
// Step 3: Create a composer.json file in the project directory with the required dependencies
// Step 4: Run 'composer install' in the project directory to install the dependencies

// composer.json file example
{
    "require": {
        "monolog/monolog": "^2.0"
    }
}