📘 What is PHP / PHP क्या है
English:
PHP stands for Hypertext Preprocessor. It is an open-source server-side scripting language mainly used for web development. PHP is executed on the server and the output is sent to the user’s browser. It is widely used for making dynamic and interactive websites.
Important Points about PHP:
- PHP is server-side scripting language.
- Full form is Hypertext Preprocessor.
- PHP code is written inside
<?php ... ?>
tags. - PHP files are saved with .php extension.
- PHP is open source (free of cost).
- It is very easy to learn compared to other languages.
- Works with almost all databases (MySQL, Oracle, PostgreSQL).
- Runs on all major operating systems (Windows, Linux, Mac).
- Supported by almost all servers (Apache, IIS).
- Can be embedded inside HTML.
- Used to build login systems and registration forms.
- Helps in making online shopping carts for e-commerce websites.
- Commonly used in Content Management Systems (CMS) like WordPress.
- Provides better security features like data encryption.
- Executes very fast compared to many other scripting languages.
- Used to create dynamic web pages that change according to user input.
- PHP can generate cookies and sessions for user management.
- It supports Object-Oriented Programming (OOPs) concepts.
- Large community support is available worldwide.
- PHP is still one of the most popular web programming languages today.
Example:
<?php
echo "Hello, World!";
?>
This code will display Hello, World! on a web page.
Hindi:
PHP का पूरा नाम Hypertext Preprocessor है। यह एक ओपन-सोर्स सर्वर-साइड स्क्रिप्टिंग भाषा है जिसका उपयोग वेब विकास (Web Development) में किया जाता है। PHP सर्वर पर चलता है और उसका परिणाम उपयोगकर्ता के ब्राउज़र पर दिखाई देता है। इसका उपयोग खासतौर पर डायनेमिक और इंटरैक्टिव वेबसाइट बनाने के लिए किया जाता है।
PHP के महत्वपूर्ण बिंदु:
- PHP एक सर्वर-साइड स्क्रिप्टिंग भाषा है।
- इसका पूरा नाम Hypertext Preprocessor है।
- PHP कोड
<?php ... ?>
टैग में लिखा जाता है। - PHP फाइल का एक्सटेंशन .php होता है।
- यह ओपन-सोर्स है यानी मुफ्त में उपलब्ध है।
- इसे सीखना बहुत ही आसान है।
- यह लगभग सभी डेटाबेस (MySQL, Oracle, PostgreSQL) के साथ काम करता है।
- यह सभी बड़े ऑपरेटिंग सिस्टम (Windows, Linux, Mac) पर चलता है।
- PHP लगभग सभी वेब सर्वर (Apache, IIS) पर काम करता है।
- इसे HTML के अंदर जोड़ा जा सकता है।
- PHP का उपयोग लॉगिन सिस्टम और रजिस्ट्रेशन फॉर्म बनाने में होता है।
- यह ई-कॉमर्स वेबसाइट के लिए शॉपिंग कार्ट बनाने में मदद करता है।
- कंटेंट मैनेजमेंट सिस्टम (CMS) जैसे WordPress PHP पर आधारित हैं।
- PHP में सुरक्षा (Security) फीचर्स भी मौजूद हैं।
- यह बहुत तेज़ गति से चलता है।
- इससे बने पेज डायनेमिक होते हैं और यूज़र इनपुट के अनुसार बदलते हैं।
- PHP में कुकीज़ और सेशन्स का उपयोग किया जा सकता है।
- यह ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग (OOPs) को सपोर्ट करता है।
- PHP का बड़ा समुदाय (Community Support) उपलब्ध है।
- आज भी PHP सबसे लोकप्रिय वेब प्रोग्रामिंग भाषाओं में से एक है।
उदाहरण:
<?php
echo "Hello, World!";
?>
📘 2. Why Conditional Statement is used in PHP / PHP में Conditional Statement क्यों उपयोग किए जाते हैं
English:
Conditional statements in PHP are used to make decisions in a program.
They allow the program to execute different code depending on certain conditions (true/false).
Without conditional statements, all code would run in the same way, but with them we can control the flow of the program.
Uses of Conditional Statements:
- To check conditions before running code.
- To compare values (equal, greater, smaller).
- To execute different blocks of code.
- To make programs more dynamic and interactive.
- To reduce repetition of code.
- Used in login systems (e.g., correct password or not).
- Useful in decision-making tasks like voting eligibility, age check.
Example in PHP:
<?php
$age = 20;
if($age >= 18){
echo "You are eligible to vote";
} else {
echo "You are not eligible to vote";
}
?>
Hindi:
PHP में Conditional statements का उपयोग प्रोग्राम में निर्णय लेने के लिए किया जाता है।
इनकी मदद से प्रोग्राम कुछ शर्तों (True/False) के आधार पर अलग-अलग कोड चला सकता है।
अगर Conditional statement न हों, तो हर कोड एक ही तरीके से चलता, लेकिन इनके उपयोग से हम प्रोग्राम के flow को नियंत्रित कर सकते हैं।
Conditional statements के उपयोग:
- कोड चलाने से पहले शर्त जाँचने के लिए।
- मानों की तुलना करने के लिए (बराबर, बड़ा, छोटा)।
- अलग-अलग कोड ब्लॉक चलाने के लिए।
- प्रोग्राम को dynamic और interactive बनाने के लिए।
- कोड को बार-बार लिखने से बचाने के लिए।
- लॉगिन सिस्टम में (जैसे पासवर्ड सही है या नहीं)।
- निर्णय लेने वाले कार्यों में (जैसे वोटिंग की योग्यता, उम्र की जाँच)।
PHP उदाहरण:
<?php
$age = 20;
if($age >= 18){
echo "आप वोट देने के योग्य हैं";
} else {
echo "आप वोट देने के योग्य नहीं हैं";
}
?>
📘 3. PHP is used for designing Dynamic Website / PHP का उपयोग Dynamic Website बनाने के लिए
English:
PHP is widely used for creating dynamic websites.
A dynamic website means a site where the content changes according to user input or database records. Unlike static websites, dynamic websites provide interaction and real-time updates.
Why PHP is used for Dynamic Websites:
- PHP runs on the server-side, so it can generate dynamic content before sending it to the browser.
- PHP can connect with databases like MySQL to fetch and display data.
- It allows user interaction through forms, login, registration, and comments.
- PHP pages can change according to user actions (e.g., shopping cart in e-commerce).
- Used in Content Management Systems (CMS) like WordPress, Joomla, Drupal.
- Provides security features for safe user interaction.
- Supports cookies and sessions to remember users.
- Easily integrates with HTML, CSS, and JavaScript.
- Makes websites more interactive and user-friendly.
- It is fast, free, and widely supported.
Example:
- Online shopping site showing different items for different users.
- News website where content updates automatically from database.
Hindi:
PHP का उपयोग डायनेमिक वेबसाइट बनाने में किया जाता है।
डायनेमिक वेबसाइट वह होती है जिसमें सामग्री (content) उपयोगकर्ता के इनपुट या डेटाबेस के रिकॉर्ड के अनुसार बदलती है।
स्टैटिक वेबसाइट में कंटेंट हमेशा एक जैसा होता है, लेकिन डायनेमिक वेबसाइट में इंटरैक्शन और रियल-टाइम अपडेट मिलते हैं।
PHP का उपयोग Dynamic Website के लिए क्यों:
- PHP सर्वर-साइड पर चलता है, इसलिए यह डायनेमिक कंटेंट जेनरेट कर सकता है।
- यह डेटाबेस (MySQL) से जुड़कर डाटा ला सकता है और दिखा सकता है।
- PHP में उपयोगकर्ता फॉर्म, लॉगिन, रजिस्ट्रेशन, कमेंट कर सकता है।
- यह यूज़र की क्रियाओं के अनुसार पेज बदल सकता है (जैसे ई-कॉमर्स शॉपिंग कार्ट)।
- CMS (WordPress, Joomla, Drupal) PHP पर आधारित हैं।
- इसमें सुरक्षा (Security) की सुविधाएँ मौजूद हैं।
- PHP में कुकीज़ और सेशन्स का उपयोग करके यूज़र को याद रखा जा सकता है।
- यह HTML, CSS, JavaScript के साथ आसानी से integrate हो जाता है।
- वेबसाइट को interactive और user-friendly बनाता है।
- यह तेज़, मुफ्त और widely supported है।
उदाहरण:
- ऑनलाइन शॉपिंग साइट, जहाँ हर यूज़र के लिए अलग-अलग प्रोडक्ट दिखते हैं।
- न्यूज़ वेबसाइट, जहाँ डेटाबेस से कंटेंट अपने आप अपडेट होता है।
📘 4. Why Session Variables are being used in PHP / PHP में Session Variables क्यों उपयोग किए जाते हैं
English:
A session variable in PHP is used to store information temporarily for a user while they browse a website.
When a user moves from one page to another, normal variables are lost, but session variables remain active until the user closes the browser or logs out.
Uses of Session Variables in PHP:
- To store user information (like username, email) during browsing.
- Useful in login systems to keep a user logged in until they log out.
- To track users while moving from one page to another.
- To maintain shopping cart data in e-commerce websites.
- For secure data handling, as session data is stored on the server.
- Helpful in personalized websites (e.g., showing user profile).
- Used for storing temporary settings or preferences.
- Sessions are more secure than cookies because data is not stored on the user’s computer.
Example in PHP:
<?php
session_start();
$_SESSION["username"] = "Gopal";
echo "Welcome " . $_SESSION["username"];
?>
👉 This code stores username in a session and displays it on the page.
Hindi:
PHP में सेशन वेरिएबल का उपयोग किसी उपयोगकर्ता की जानकारी को अस्थायी रूप से सहेजने (store) के लिए किया जाता है।
जब यूज़र एक पेज से दूसरे पेज पर जाता है तो सामान्य वेरिएबल खो जाते हैं, लेकिन सेशन वेरिएबल तब तक बने रहते हैं जब तक ब्राउज़र बंद न हो जाए या यूज़र लॉग आउट न कर दे।
PHP में Session Variables के उपयोग:
- यूज़र की जानकारी (जैसे नाम, ईमेल) को ब्राउज़िंग के दौरान सुरक्षित रखना।
- लॉगिन सिस्टम में उपयोगकर्ता को लॉगिन स्थिति में रखना।
- जब यूज़र एक पेज से दूसरे पेज पर जाए तो उसका track रखना।
- ई-कॉमर्स वेबसाइट में shopping cart data को बनाए रखना।
- सुरक्षित डेटा हैंडलिंग, क्योंकि session data सर्वर पर स्टोर होता है।
- पर्सनलाइज्ड वेबसाइट (जैसे user profile दिखाना) बनाने में।
- अस्थायी सेटिंग्स या preferences स्टोर करने में।
- सेशन कुकीज़ से ज्यादा सुरक्षित होते हैं क्योंकि डेटा यूज़र के कंप्यूटर पर नहीं बल्कि सर्वर पर रहता है।
PHP उदाहरण:
<?php
session_start();
$_SESSION["username"] = "Gopal";
echo "स्वागत है " . $_SESSION["username"];
?>
👉 यह कोड यूज़रनेम को सेशन में स्टोर करेगा और पेज पर दिखाएगा।
📘 5. What is Function and Why Function is used in PHP / PHP में Function क्या है और इसका उपयोग क्यों किया जाता है
English:
A function in PHP is a block of code that performs a specific task.
Instead of writing the same code again and again, we can put it inside a function and call it whenever needed.
Functions make programs shorter, easier to read, and reusable.
Why Functions are used in PHP:
- To avoid repetition of code.
- To make programs organized and readable.
- To reuse code multiple times.
- To make debugging and error fixing easier.
- To divide a large program into smaller parts.
- Functions save time and effort.
- Some functions are predefined in PHP (like
strlen()
,date()
,count()
). - Users can also create custom functions.
Example of Function in PHP:
<?php
function greet(){
echo "Hello, Welcome to PHP!";
}
greet(); // Calling the function
?>
👉 Output: Hello, Welcome to PHP!
Hindi:
PHP में फ़ंक्शन कोड का वह ब्लॉक होता है जो किसी विशेष कार्य को करता है।
एक ही कोड को बार-बार लिखने की बजाय, उसे एक फ़ंक्शन में डालकर जरूरत पड़ने पर बुलाया (call) जा सकता है।
फ़ंक्शन प्रोग्राम को छोटा, पढ़ने योग्य और बार-बार उपयोग करने योग्य बनाते हैं।
PHP में Functions के उपयोग:
- कोड की repetition (दोहराव) से बचने के लिए।
- प्रोग्राम को संगठित और पढ़ने योग्य बनाने के लिए।
- एक ही कोड को बार-बार उपयोग करने के लिए।
- डिबगिंग और त्रुटियों को ठीक करना आसान हो जाता है।
- बड़े प्रोग्राम को छोटे भागों में बाँटने के लिए।
- समय और मेहनत की बचत होती है।
- PHP में पहले से बने predefined functions होते हैं (जैसे
strlen()
,date()
,count()
)। - यूज़र अपने custom functions भी बना सकता है।
PHP का उदाहरण:
<?php
function greet(){
echo "नमस्ते, PHP में आपका स्वागत है!";
}
greet(); // फ़ंक्शन को कॉल करना
?>
👉 Output: नमस्ते, PHP में आपका स्वागत है!
Q7. Difference between WHILE loop and DO WHILE loop in PHP
English Table
Feature | WHILE Loop | DO WHILE Loop |
---|---|---|
Definition | WHILE loop checks condition first, then executes code. | DO WHILE loop executes code first, then checks condition. |
Condition Check | Condition is checked before execution. | Condition is checked after execution. |
Minimum Execution | May not run even once if condition is false. | Runs at least one time even if condition is false. |
Usage | Used when number of iterations is not fixed and may be zero. | Used when code must run at least once. |
Syntax | while(condition){ //code } | do{ //code } while(condition); |
Flow | Condition → Execution | Execution → Condition |
Speed | Slightly faster because it checks before running. | Slightly slower because it executes first. |
Example | Printing table only if number > 0. | Showing menu at least once even if user exits. |
Practical Use | Useful when we are not sure loop should run. | Useful when we want loop to run once in every case. |
Common Mistake | Beginners forget condition may never execute. | Beginners forget it always executes once. |
Hindi Table
विशेषता (Feature) | WHILE Loop | DO WHILE Loop |
---|---|---|
परिभाषा | WHILE loop पहले condition check करता है फिर code चलाता है। | DO WHILE loop पहले code चलाता है फिर condition check करता है। |
Condition Check | Condition पहले check होती है। | Condition बाद में check होती है। |
Minimum Execution | Condition false होने पर loop एक बार भी नहीं चलेगा। | Loop कम से कम एक बार चलेगा चाहे condition false हो। |
Usage | जब iterations की संख्या fix नहीं है और zero भी हो सकती है। | जब code को हर हाल में एक बार चलाना है। |
Syntax | while(condition){ //code } | do{ //code } while(condition); |
Flow | Condition → Execution | Execution → Condition |
Speed | तेज, क्योंकि पहले check करता है। | थोड़ा slow, क्योंकि पहले execute करता है। |
Example | केवल तब table print करना जब number > 0 हो। | Menu ek baar show करना चाहे user exit कर दे। |
Practical Use | जब हमें doubt हो loop चलेगा या नहीं। | जब हमें guarantee हो ek baar to code चले ही। |
Common Mistake | Condition false होने पर beginners confuse हो जाते हैं। | Beginners भूल जाते हैं कि ये हमेशा ek baar चलता है। |
Q8. How can you write script in PHP
English Explanation
- PHP Script Block – A PHP script is written inside
<?php ... ?>
tags. - Server-side Execution – The code runs on the server and then sends the output (HTML/text) to the browser.
- File Extension – PHP script must be saved with
.php
extension (e.g.,index.php
). - Basic Example –
<?php
echo "Hello PHP!";
?>
- Echo Statement – We use
echo
orprint
to display output in PHP. - Combination with HTML – PHP can be mixed with HTML in the same file.
<html>
<body>
<?php echo "Welcome to PHP"; ?>
</body>
</html>
- Case Sensitivity – PHP variables are case-sensitive (
$name
and$Name
are different). - Comments – We can write comments using
//
(single line) or/* ... */
(multi-line). - Server Required – To run PHP scripts, we need a server like WAMP, XAMPP, or LAMP.
- Output Check – After saving
.php
file, open it in browser usinghttp://localhost/filename.php
.
Hindi Explanation
- PHP Script Block – PHP script
<?php ... ?>
टैग्स के बीच लिखी जाती है। - Server-side Execution – Code server पर चलता है और browser को HTML या text output भेजता है।
- File Extension – PHP script को
.php
extension से save करना ज़रूरी है (जैसेindex.php
)। - Basic Example –
<?php
echo "Hello PHP!";
?>
- Echo Statement – Output दिखाने के लिए
echo
याprint
का use करते हैं। - HTML के साथ Combination – PHP को HTML के साथ same file में use किया जा सकता है।
<html>
<body>
<?php echo "Welcome to PHP"; ?>
</body>
</html>
- Case Sensitivity – PHP variables case-sensitive होते हैं (
$name
और$Name
अलग हैं)। - Comments – Comments लिखने के लिए
//
(single line) और/* ... */
(multi-line) का use होता है। - Server की आवश्यकता – PHP script चलाने के लिए server चाहिए जैसे WAMP, XAMPP, LAMP।
- Output Check करना – File save करने के बाद browser में
http://localhost/filename.php
से run करना होता है।
Q9. What is Form and How to Create it in PHP?
Answer (English Explanation – 10 Points)
- Definition – A form is an area on a web page that allows users to enter data.
- Purpose – Forms are used to collect user inputs like name, email, password, feedback.
- HTML Form Tag – Forms are created using
<form> ... </form>
tag. - Action Attribute – Defines the page where data will be sent (example:
action="submit.php"
). - Method Attribute – Tells how data will be sent:
GET
orPOST
. - Input Fields – Forms use input fields like text box, radio button, checkbox, password, submit button.
- Basic Example –
<form method="post" action="submit.php">
Name: <input type="text" name="uname"><br>
<input type="submit" value="Submit">
</form>
- Server-side Handling – PHP script receives this form data using
$_GET
or$_POST
. - Security – Always validate and secure the form data to avoid hacking (SQL Injection).
- Practical Use – Login forms, Registration forms, Feedback forms, Contact forms.
Answer (Hindi Explanation – 10 Points)
- परिभाषा (Definition) – Form एक web page पर वह जगह है जहाँ user data भर सकता है।
- उद्देश्य (Purpose) – Form का use user से input लेने के लिए होता है जैसे नाम, ईमेल, पासवर्ड।
- HTML Form Tag – Form बनाने के लिए
<form> ... </form>
tag का use होता है। - Action Attribute – बताता है data किस page को भेजना है (उदाहरण:
action="submit.php"
)। - Method Attribute – बताता है data कैसे भेजना है:
GET
याPOST
method से। - Input Fields – Form में input fields होते हैं जैसे textbox, radio button, checkbox, password, submit button।
- Basic Example –
<form method="post" action="submit.php">
नाम: <input type="text" name="uname"><br>
<input type="submit" value="Submit">
</form>
- Server-side Handling – PHP script data को
$_GET
या$_POST
से receive करता है। - Security (सुरक्षा) – Form data को हमेशा validate और secure करना चाहिए ताकि hacking (SQL Injection) न हो।
- Practical Use (व्यावहारिक उपयोग) – Login form, Registration form, Feedback form, Contact form।
Q10. What is Variable, Naming Rules & How to Declare it in PHP?
Answer (English Explanation)
A variable in PHP is a container used to store data temporarily in memory. It can hold different types of values like numbers, strings, or arrays. Variables make programs dynamic because we can reuse and update their values at any time.
Naming Rules for Variables in PHP:
- A variable always starts with a
$
sign. - The name must begin with a letter or underscore (
_
). - It cannot start with a number.
- No spaces are allowed in the variable name.
- Special characters (like
@, %, -
) are not allowed. - Variable names are case-sensitive (
$Name
and$name
are different). - Use meaningful names for better readability.
- Keywords (like
if, while, for
) cannot be used as variable names. - Variables can store different data types (int, string, array, etc.).
- Default value is
NULL
if no value is assigned.
Declaration Example:
<?php
$name = "Gopal"; // String
$age = 20; // Integer
$isStudent = true; // Boolean
?>
Answer (Hindi Explanation)
PHP में Variable एक container (डिब्बा) होता है जिसमें हम अस्थायी रूप से data store करते हैं। यह data numbers, strings, arrays आदि हो सकता है। Variable program को dynamic बनाता है क्योंकि हम values को बार-बार बदल सकते हैं और reuse कर सकते हैं।
Variable Naming Rules (नियम):
- Variable हमेशा
$
sign से शुरू होता है। - नाम letter या underscore (
_
) से शुरू होना चाहिए। - यह number से शुरू नहीं हो सकता।
- Variable के नाम में spaces नहीं होने चाहिए।
- Special characters (जैसे
@, %, -
) नहीं होने चाहिए। - Variable नाम case-sensitive होते हैं (
$Name
और$name
अलग हैं)। - अच्छे readability के लिए meaningful नाम रखने चाहिए।
- Keywords (जैसे
if, while, for
) को variable नाम नहीं बना सकते। - Variable अलग-अलग data types रख सकता है (जैसे int, string, array)।
- अगर value assign नहीं की तो default value
NULL
होगी।
Declaration Example (उदाहरण):
<?php
$name = "Gopal"; // String
$age = 20; // Integer
$isStudent = true; // Boolean
?>
11. What is Loop and Loops in PHP?
English Explanation:
- A loop in PHP is used to execute a block of code repeatedly, as long as a certain condition is true.
- It helps to reduce repetition of code. Instead of writing the same line again and again, we put it inside a loop.
- PHP supports different types of loops for different needs.
Types of Loops in PHP:
- while loop → Executes a block of code as long as the condition is true.
- do…while loop → Executes the block of code once, then checks the condition.
- for loop → Used when we know how many times we want to run the loop.
- foreach loop → Specially used to loop through arrays.
Example (for loop):
<?php
for($i=1; $i<=5; $i++){
echo "This is line $i <br>";
}
?>
Output:
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
Hindi Explanation:
- PHP में loop का use बार-बार code चलाने के लिए किया जाता है।
- अगर हमें कोई काम 10 बार repeat करना है, तो 10 बार code लिखने की ज़रूरत नहीं है।
- बस एक बार code लिखो और loop में डाल दो, वो बार-बार run होगा।
PHP में loops के प्रकार:
- while loop → जब तक condition true है, code चलता है।
- do…while loop → पहले code चलता है, फिर condition check होती है।
- for loop → जब हमें पता हो code कितनी बार चलाना है।
- foreach loop → Array के elements को access करने के लिए।
उदाहरण (for loop):
<?php
for($i=1; $i<=5; $i++){
echo "यह लाइन $i है <br>";
}
?>
आउटपुट:
यह लाइन 1 है
यह लाइन 2 है
यह लाइन 3 है
यह लाइन 4 है
यह लाइन 5 है
12. What is Operator in PHP and Types of Operator
English Explanation
In PHP, an operator is a symbol that tells the PHP engine to perform specific operations on variables or values.
For example: +
, -
, *
, /
, =
etc.
Operators are mainly used in expressions to calculate values, compare data, or assign results.
Types of Operators in PHP
- Arithmetic Operators – Used for mathematical calculations.
+
(Addition)-
(Subtraction)*
(Multiplication)/
(Division)%
(Modulus) Example:
<?php
$a = 10;
$b = 3;
echo $a + $b; // 13
echo $a % $b; // 1
?>
- Assignment Operators – Used to assign values to variables.
=
(Simple assignment)+=
(Add and assign)-=
(Subtract and assign)*=
(Multiply and assign)/=
(Divide and assign) Example:
<?php
$x = 5;
$x += 3; // $x = 8
echo $x;
?>
- Comparison Operators – Used to compare values.
==
(Equal)===
(Identical – checks value and type)!=
or<>
(Not equal)>
(Greater than)<
(Less than)>=
(Greater than or equal)<=
(Less than or equal) Example:
<?php
$a = 10;
$b = 20;
var_dump($a == $b); // false
var_dump($a < $b); // true
?>
- Logical Operators – Used to combine conditions.
&&
orand
(Logical AND)||
oror
(Logical OR)!
(Logical NOT) Example:
<?php
$age = 20;
if ($age >= 18 && $age <= 60) {
echo "Eligible";
}
?>
- Increment/Decrement Operators – Used to increase or decrease values.
++$x
(Pre-increment)$x++
(Post-increment)--$x
(Pre-decrement)$x--
(Post-decrement)
- String Operators – Used with strings.
.
(Concatenation – joins two strings).=
(Concatenation assignment) Example:
<?php
$name = "PHP";
$msg = "Hello " . $name;
echo $msg; // Hello PHP
?>
- Array Operators – Used with arrays.
+
(Union)==
(Equal)===
(Identical)!=
or<>
(Not equal)!==
(Not identical)
- Error Control Operator –
@
is used to suppress error messages.
Hindi Explanation (हिंदी में)
PHP में operator (ऑपरेटर) ऐसे symbols होते हैं जिनका उपयोग किसी calculation, comparison या assignment के लिए किया जाता है।
उदाहरण: +
, -
, *
, /
, =
आदि।
Operators के प्रकार:
- Arithmetic Operators → गणितीय गणना के लिए
- Assignment Operators → वैल्यू असाइन करने के लिए
- Comparison Operators → तुलना करने के लिए
- Logical Operators → Conditions जोड़ने के लिए
- Increment/Decrement Operators → Value बढ़ाने/घटाने के लिए
- String Operators → Strings जोड़ने के लिए
- Array Operators → Arrays compare करने के लिए
- Error Control Operator → Errors छुपाने के लिए
📌 In Short: Operators are building blocks in PHP to perform calculations, comparisons, and logic in programs.
13. Program using Switch Statement
English Explanation:
In PHP, the switch statement is used when we have to compare one expression with multiple possible values. Instead of writing many if...else
statements, switch makes the program more clear and readable.
Syntax:
switch(expression) {
case value1:
// code to execute if expression == value1
break;
case value2:
// code to execute if expression == value2
break;
default:
// code if no match found
}
Hindi Explanation (हिंदी में):
PHP में switch statement का प्रयोग तब किया जाता है जब हमें एक ही expression को कई अलग-अलग values से compare करना हो। यह कई सारे if...else
लिखने से आसान और साफ तरीका है।
Example Program:
<?php
$day = "Tuesday";
switch($day) {
case "Monday":
echo "Today is Monday.";
break;
case "Tuesday":
echo "Today is Tuesday.";
break;
case "Wednesday":
echo "Today is Wednesday.";
break;
default:
echo "Invalid day!";
}
?>
Output (यदि $day = "Tuesday"
है):
Today is Tuesday.
✅ Summary (सारांश):
- Switch statement एक expression को कई cases से मिलाकर check करता है।
- हर case के बाद
break
लगाना ज़रूरी है ताकि control बाहर निकल जाए। - अगर कोई match नहीं होता तो
default
वाला block चलता है।
14. What is WAMP Server? / WAMP Server क्या है?
Answer (English):
WAMP Server is a software package that works on Windows operating system. It includes:
- W → Windows
- A → Apache (Web Server)
- M → MySQL (Database Server)
- P → PHP (Scripting Language)
It creates a local server environment, where we can run and test our PHP programs and websites without uploading them to the internet.
👉 In simple words: WAMP Server is used to run and test websites or PHP projects on a local computer.
उत्तर (हिंदी):
WAMP Server एक सॉफ्टवेयर पैकेज है जो Windows ऑपरेटिंग सिस्टम पर काम करता है। इसमें चार भाग होते हैं:
- W → Windows
- A → Apache (वेब सर्वर)
- M → MySQL (डेटाबेस सर्वर)
- P → PHP (स्क्रिप्टिंग भाषा)
यह एक लोकल सर्वर वातावरण तैयार करता है, जहाँ हम अपने PHP प्रोग्राम और वेबसाइट को इंटरनेट पर अपलोड किए बिना ही अपने कंप्यूटर पर चला और टेस्ट कर सकते हैं।
👉 आसान भाषा में: WAMP Server का उपयोग वेबसाइट या PHP प्रोजेक्ट को लोकल कंप्यूटर पर चलाने और जाँच करने के लिए किया जाता है।
15. Data Types in PHP
English Explanation
In PHP, data types define the type of data a variable can store.
PHP supports different data types, and they are mainly divided into 8 types.
Types of Data Types in PHP
- Integer – Whole numbers (example: 10, -20).
- Float/Double – Decimal numbers (example: 10.5, -3.14).
- String – Sequence of characters (example: “Hello World”).
- Boolean – True or False values.
- Array – Collection of multiple values in a single variable.
- Object – Instance of a class (OOP concept).
- NULL – A variable with no value.
- Resource – Special type holding external references like database connections.
👉 Example:
<?php
$age = 25; // Integer
$price = 55.75; // Float
$name = "Gopal"; // String
$is_student = true; // Boolean
$fruits = array("Apple", "Mango", "Banana"); // Array
?>
हिंदी :
PHP में Data Types का मतलब है कि एक variable किस प्रकार का डेटा (मूल्य) स्टोर कर सकता है।
PHP में अलग-अलग तरह के data types होते हैं, जो मुख्य रूप से 8 प्रकार के हैं।
PHP के Data Types
- Integer (पूर्णांक) – केवल पूरे अंक (जैसे 10, -20)।
- Float/Double (दशमलव संख्या) – दशमलव वाली संख्या (जैसे 10.5, -3.14)।
- String (पाठ्य/अक्षर श्रृंखला) – शब्द या अक्षरों का समूह (जैसे “Hello World”)।
- Boolean (सत्य/असत्य) – केवल True या False।
- Array (सरणी) – एक variable में कई मानों का समूह।
- Object (ऑब्जेक्ट) – किसी class का instance (OOP concept)।
- NULL (शून्य मान) – ऐसा variable जिसका कोई मान नहीं है।
- Resource (संसाधन) – बाहरी स्रोत जैसे database connection को स्टोर करने के लिए।
👉 उदाहरण:
<?php
$umra = 25; // Integer (पूर्णांक)
$daam = 55.75; // Float (दशमलव संख्या)
$naam = "Gopal"; // String (अक्षर श्रृंखला)
$vidyarthi_hai = true; // Boolean (सत्य/असत्य)
$phal = array("Apple", "Mango", "Banana"); // Array (सरणी)
?>