What is the purpose of namespaces in PHP and how are they used?

Namespaces in PHP are used to avoid naming conflicts between classes, functions, and constants. They allow you to organize your code into logical groupings and prevent naming collisions when using code from different sources. To use namespaces in PHP, you simply define them at the beginning of your file using the `namespace` keyword.

<?php

namespace MyNamespace;

class MyClass {
    // class implementation
}

function myFunction() {
    // function implementation
}

const MY_CONSTANT = "value";

?>