Is it possible to define a function within another function in PHP?

Yes, it is possible to define a function within another function in PHP. This is known as a nested function. Nested functions can be useful for encapsulating functionality that is only relevant within the scope of the outer function. To define a nested function, simply declare the inner function inside the body of the outer function.

function outerFunction() {
    function innerFunction() {
        // Function logic here
    }

    // Call the inner function
    innerFunction();
}

// Call the outer function
outerFunction();