How can PHP be used to return multiple values in a function?

In PHP, a function can only return a single value. To return multiple values from a function, you can use an array or an object to encapsulate all the values and return that instead. This allows you to effectively return multiple values in a structured way.

function getMultipleValues() {
    $value1 = 10;
    $value2 = 'Hello';
    $values = [$value1, $value2];
    return $values;
}

// Usage
list($result1, $result2) = getMultipleValues();
echo $result1; // Output: 10
echo $result2; // Output: Hello