Can you explain the concept of passing parameters to functions in PHP with an example?
When passing parameters to functions in PHP, you can specify the parameters that the function expects to receive when it is called. These parameters can be used within the function to perform specific tasks or calculations. By passing parameters to functions, you can make your code more modular and reusable. Example:
<?php
// Define a function that takes two parameters
function addNumbers($num1, $num2) {
$sum = $num1 + $num2;
echo "The sum of $num1 and $num2 is: $sum";
}
// Call the function with specific values as parameters
addNumbers(5, 10);
?>
Related questions
-
ORM application design PHP
-
iframes PHP scripts compatibility
-
unlink() file deletion security vulnerability