Google News
logo
PHP Program to Function with one argument
In the following example of PHP program that demonstrates a function with one argument :
Program :
<?php

// Declare a function
function square($num) {
    return $num * $num;
}

// Call the function
$result = square(5);

// Print the result
echo "The square of 5 is: $result";

?>
Output :
The square of 5 is: 25
In the above example, we have declared a function `square` that takes one parameter `$num`. Inside the function, we calculate the square of the number using the multiplication operator and return it using the `return` statement. We then call the function with argument `5` and assign the result to the variable `$result`.

Finally, we print out the result using the `echo` statement.