What is the difference between include, include_once, require, and require_once? include, include_once, require और require_once में क्या अंतर है?
Short Answer
Parameters allow you to pass data into a function so that the function can process that specific data. They act as variables inside the function scope.
Detailed Explanation & Code Example
When you define a function, you can specify one or more parameters inside the parentheses. When you call the function, you pass arguments to match those parameters.
// Defining a function with two parameters: $name and $greeting
function greetUser($name, $greeting) {
echo "$greeting, $name!";
}
// Calling the function and passing arguments
greetUser("Alice", "Hello");
// Output: Hello, Alice!
greetUser("Bob", "Good morning");
// Output: Good morning, Bob!
Important Points
In modern PHP (7.0+), it is highly recommended to use Type Declarations to ensure the correct data types are passed to your parameters:
// Enforces that $age must be an integer
function setAge(int $age) {
// ...
}
| स्टेटमेंट | फाइल न मिलने पर | दोबारा शामिल करना |
|---|---|---|
include | वार्निंग, स्क्रिप्ट चलती रहती है | हर बार शामिल करता है |
include_once | वार्निंग, स्क्रिप्ट चलती रहती है | पहले से शामिल हो तो स्किप |
require | फेटल एरर, स्क्रिप्ट रुक जाती है | हर बार शामिल करता है |
require_once | फेटल एरर, स्क्रिप्ट रुक जाती है | पहले से शामिल हो तो स्किप |
इंटरव्यू टिप: क्लास डेफिनिशन या कॉन्फ़िग फाइल्स जैसी क्रिटिकल फाइल्स के लिए require_once इस्तेमाल करें, और फुटर टेम्पलेट जैसी ऑप्शनल फाइल्स के लिए include।
Was this answer clear?