What is the difference between const and define in PHP?

In PHP, the main difference between const and define is that const is a language construct used to define constants within classes, while define is a function used to define constants outside of classes. Const is a compile-time constant, meaning it can only be assigned scalar values, while define allows for more complex expressions. Const is also scoped to the class it is defined in, while define is global in scope.

// Using const to define a constant within a class
class MyClass {
    const MY_CONSTANT = 'Hello';
}

// Using define to define a constant outside of a class
define('MY_CONSTANT', 'Hello');