What is the significance of defining a function in PHP and how does it affect the output of the code?

Defining a function in PHP allows you to encapsulate a block of code that can be reused multiple times throughout your program. This helps in organizing your code, improving readability, and reducing redundancy. When a function is defined, you can call it multiple times with different inputs, and it will execute the same block of code each time, providing consistent output.

// Defining a function in PHP
function addNumbers($num1, $num2) {
    return $num1 + $num2;
}

// Calling the function
$result = addNumbers(5, 3);
echo $result; // Output: 8