What are the best practices for organizing functions and calculations in a separate file in PHP?
When working on a PHP project, it is a good practice to organize functions and calculations in a separate file to improve code readability and maintainability. This can be achieved by creating a separate PHP file specifically for functions and including it in your main PHP file using the `require_once` or `include_once` statement.
// functions.php
<?php
function calculateSum($num1, $num2) {
return $num1 + $num2;
}
function calculateProduct($num1, $num2) {
return $num1 * $num2;
}
// main.php
<?php
require_once 'functions.php';
$num1 = 10;
$num2 = 5;
$sum = calculateSum($num1, $num2);
$product = calculateProduct($num1, $num2);
echo "Sum: $sum, Product: $product";