PHP Functions
User-defined functions in PHP let you group code into reusable blocks. They improve readability and reduce repetition.
PHP में user-defined functions का उपयोग कोड को दोबारा उपयोग करने योग्य ब्लॉकों में विभाजित करने के लिए किया जाता है। इससे कोड समझने और दोहराव से बचने में मदद मिलती है।
Basic Function
Create and call a simple function.
एक सामान्य function बनाएं और कॉल करें।
<?php
function greet() {
echo "Hello, User!";
}
greet();
?>
Hello, User!
Function with Parameters
Functions can take input values (parameters).
Functions इनपुट (parameters) ले सकते हैं।
<?php
function welcome($name) {
echo "Welcome, $name!";
}
welcome("Rahul");
?>
Welcome, Rahul!
Function with Return
Functions can return a value to the caller.
Functions एक मान (value) वापिस कर सकते हैं।
<?php
function add($a, $b) {
return $a + $b;
}
$result = add(5, 10);
echo $result;
?>
15