Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 7 of 13 · PHP Basics & Syntax
Interview question

What is the difference between include, include_once, require, and require_once? include, include_once, require और require_once में क्या अंतर है?

Answer

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?