Skip to content

Defining Function

Functions are reusable blocks of code that perform specific tasks. They help organize code, reduce repetition, and make programs easier to maintain.

<?php
// Basic function definition
function sayHello() {
echo "Hello, World!";
}
// Calling a function
sayHello(); // Hello, World!
<?php
function getGreeting() {
return "Hello, World!";
}
$message = getGreeting();
echo $message; // Hello, World!