Related Topics

what is Protocols in Hindi

What is a Program in Hindi

What is a Secure Connection in Hindi

Introduction to WWW in Hindi

What are Development Tools in Hindi

What is a Web Browser in Hindi

What is a Server in Hindi

What is a UNIX Web Server in Hindi

What is Logging Users in Hindi

What is Dynamic IP Web Design in Hindi

Web Site Design Principles in Hindi

Introduction to Site Planning and Navigation in Hindi

what is Web Systems Architecture in Hindi

Architecture of Web-Based Systems in Hindi

Client-Server Architecture in Hindi

What is Caching in Hindi

: Proxies in Hindi

What is an Index in Hindi

What is a Load Balancer in Hindi

What is a Queue in Hindi

Web Application Architecture in Hindi

JavaScript in Hindi

Client-Side Scripting in Hindi

Introduction to Simple JavaScript in Hindi

: JavaScript Variables in Hindi

What is a Function in JavaScript in Hindi

What are Conditions in JavaScript in Hindi

What are Loops in JavaScript in Hindi

What is Repetition (Looping) in JavaScript? in Hindi

What is an Object in JavaScript in Hindi

JavaScript Own Objects in Hindi

What is DOM in Hindi

What is a Web Browser Environment in Hindi

Forms in JavaScript in Hindi

DHTML in Hindi

What are Events in DHTML in Hindi

Browser Control in JavaScript in Hindi

AJAX in Hindi

AJAX-based Web Application in Hindi

Alternatives to AJAX in Hindi

XML in Hindi

Uses of XML in Hindi

Simple XML in Hindi

XML Key Components in Hindi

What is DTD (Document Type Definition) in Hindi

What is XML Schema (XSD) in Hindi

XML with Application in Hindi

XSL in Hindi

XSLT in Hindi

Web Service in hindi

PHP in Hindi

Server-Side Scripting in Hindi

PHP Arrays in Hindi

PHP Forms in Hindi

Advanced PHP Databases in Hindi

Introduction to Basic Commands in PHP in Hindi

Server Connection in PHP in Hindi

Database Creation in PHP in Hindi

Understanding Database Selection in PHP in Hindi

PHPMyAdmin in Hindi

Database Bugs in Hindi

PHP Database Query in Hindi

Related Subjects

PHP Functions in Hindi

DIPLOMA_CSE / Web Technology

PHP Functions in Hindi

What is a Function in PHP?

PHP рдореЗрдВ function рдПрдХ block рд╣реЛрддрд╛ рд╣реИ, рдЬрд┐рд╕реЗ рдЖрдк рдмрд╛рд░-рдмрд╛рд░ рдЙрдкрдпреЛрдЧ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕реЗ рд╣рдо рдПрдХ рдкреНрд░рдХрд╛рд░ рд╕реЗ code рдХреЛ рдПрдХ рдирд╛рдо рджреЗ рджреЗрддреЗ рд╣реИрдВ, рддрд╛рдХрд┐ рдЙрд╕ function рдХреЛ рдХрд╣реАрдВ рднреА call рдХрд░рдХреЗ рд╣рдо рдЕрдкрдиреА рдЬрд░реБрд░рдд рдХреЗ рд╣рд┐рд╕рд╛рдм рд╕реЗ use рдХрд░ рд╕рдХреЗрдВред PHP functions рдХреЛ user-defined function рднреА рдХрд╣рддреЗ рд╣реИрдВ рдХреНрдпреЛрдВрдХрд┐ рд╣рдо рдЗрдиреНрд╣реЗрдВ рдЦреБрдж define рдХрд░рддреЗ рд╣реИрдВред

Types of Functions in PHP

  • Built-in Functions: PHP рдореЗрдВ рдкрд╣рд▓реЗ рд╕реЗ рдХрдИ predefined functions рд╣реЛрддреЗ рд╣реИрдВ рдЬреИрд╕реЗ echo(), strlen(), etc. рдЬреЛрдХрд┐ PHP рджреНрд╡рд╛рд░рд╛ рдмрдирд╛рдП рдЬрд╛рддреЗ рд╣реИрдВред
  • User-defined Functions: рдпреЗ рд╡реЛ functions рд╣реЛрддреЗ рд╣реИрдВ рдЬрд┐рдиреНрд╣реЗрдВ рд╣рдо рдЕрдкрдиреА рдЬрд╝рд░реВрд░рдд рдХреЗ рд╣рд┐рд╕рд╛рдм рд╕реЗ рдмрдирд╛рддреЗ рд╣реИрдВред рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП, рдпрджрд┐ рд╣рдореЗрдВ рджреЛ numbers рдХрд╛ sum calculate рдХрд░рдирд╛ рд╣реИ, рддреЛ рд╣рдо рдПрдХ function рдмрдирд╛ рд╕рдХрддреЗ рд╣реИрдВред

How to Define a Function in PHP?

Function рдХреЛ define рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП PHP рдореЗрдВ function keyword рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реИрдВред рдЗрд╕рдХреЗ рдмрд╛рдж function рдХрд╛ рдирд╛рдо рдФрд░ рдкреИрд░рд╛рдореАрдЯрд░ (рдпрджрд┐ рдЬрд╝рд░реВрд░рдд рд╣реЛ) рд▓рд┐рдЦрддреЗ рд╣реИрдВред


function sum($a, $b) {
    return $a + $b;
}
        

рдпрд╣ function рджреЛ arguments $a рдФрд░ $b рд▓реЗрддрд╛ рд╣реИ рдФрд░ рдЙрдирдХрд╛ sum return рдХрд░рддрд╛ рд╣реИред

Function Parameters in PHP

What are Function Parameters?

Function parameters рд╡рд╣ variables рд╣реЛрддреЗ рд╣реИрдВ рдЬрд┐рдиреНрд╣реЗрдВ рд╣рдо function рдХреЗ рдЕрдВрджрд░ pass рдХрд░рддреЗ рд╣реИрдВред рдпреЗ parameters function рдХреЛ values provide рдХрд░рддреЗ рд╣реИрдВ рддрд╛рдХрд┐ function рдЕрдкрдиреЗ рдХрд╛рдо рдХреЛ рдкреВрд░рд╛ рдХрд░ рд╕рдХреЗред PHP рдореЗрдВ, function parameters рдХреЛ function definition рдХреЗ рджреМрд░рд╛рди specify рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

Types of Function Parameters

  • Default Parameters: рдЬрдм рд╣рдо function рдХреЛ define рдХрд░рддреЗ рд╕рдордп parameter рдХреЛ рдПрдХ default value рджреЗрддреЗ рд╣реИрдВ, рддреЛ рдЙрд╕ value рдХрд╛ рдЙрдкрдпреЛрдЧ рддрдм рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рдЬрдм caller рдиреЗ рдХреЛрдИ value рдирд╣реАрдВ рджреА рд╣реЛред
  • 
    function greet($name = "Guest") {
        echo "Hello, $name!";
    }
                
  • Required Parameters: рдпреЗ parameters function рдХреЛ call рдХрд░рддреЗ рд╕рдордп mandatory рд╣реЛрддреЗ рд╣реИрдВред рдпрджрд┐ function call рдХреЗ рджреМрд░рд╛рди рдЗрди parameters рдХреА values рдирд╣реАрдВ рджреА рдЬрд╛рддреА рд╣реИрдВ, рддреЛ error рд╣реЛ рдЬрд╛рддрд╛ рд╣реИред
  • Variable-length Parameters: рдЗрди parameters рдХрд╛ рдЙрдкрдпреЛрдЧ рд╣рдо рддрдм рдХрд░рддреЗ рд╣реИрдВ рдЬрдм рд╣рдореЗрдВ function рдореЗрдВ рдПрдХ рд╕реЗ рдЬрд╝реНрдпрд╛рджрд╛ argument pass рдХрд░рдиреЗ рд╣реЛрддреЗ рд╣реИрдВред PHP рдореЗрдВ func_num_args() рдФрд░ func_get_arg() рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред
  • 
    function sumNumbers() {
        $total = 0;
        for($i = 0; $i < func_num_args(); $i++) {
            $total += func_get_arg($i);
        }
        return $total;
    }
                

PHP Function Arguments in Hindi

What are Function Arguments?

Function arguments рд╡рд╣ values рд╣реЛрддреА рд╣реИрдВ рдЬрд┐рдиреНрд╣реЗрдВ рд╣рдо function рдХреЛ call рдХрд░рддреЗ рд╕рдордп pass рдХрд░рддреЗ рд╣реИрдВред рдЗрди arguments рдХреА рдорджрдж рд╕реЗ function рдХреЛ рдХрд╛рдо рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП input рдорд┐рд▓рддрд╛ рд╣реИред Function arguments рдХреЛ parameters рд╕реЗ differentiate рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рдХреНрдпреЛрдВрдХрд┐ arguments function рдХреЛ call рдХрд░рддреЗ рд╕рдордп рджрд┐рдП рдЬрд╛рддреЗ рд╣реИрдВ, рдЬрдмрдХрд┐ parameters function definition рдореЗрдВ рд╣реЛрддреЗ рд╣реИрдВред

Passing Arguments by Value and by Reference

  • Passing Arguments by Value: рдЬрдм рд╣рдо arguments рдХреЛ value рдХреЗ рд░реВрдк рдореЗрдВ pass рдХрд░рддреЗ рд╣реИрдВ, рддреЛ function рдХреЗ рдЕрдВрджрд░ рдЙрди arguments рдХреА values рдХреЛ modify рдХрд░рдирд╛ function рдХреЗ рдмрд╛рд╣рд░ рдХрд┐рд╕реА рддрд░рд╣ рд╕реЗ impact рдирд╣реАрдВ рдХрд░рддрд╛ред
  • 
    function changeValue($a) {
        $a = 10;
    }
    $num = 5;
    changeValue($num);
    echo $num; // Output: 5
                
  • Passing Arguments by Reference: рдЬрдм рд╣рдо arguments рдХреЛ reference рдХреЗ рд░реВрдк рдореЗрдВ pass рдХрд░рддреЗ рд╣реИрдВ, рддреЛ function рдХреЗ рдЕрдВрджрд░ рдХрд┐рдП рдЧрдП changes function рдХреЗ рдмрд╛рд╣рд░ рднреА reflect рд╣реЛрддреЗ рд╣реИрдВред
  • 
    function changeValue(&$a) {
        $a = 10;
    }
    $num = 5;
    changeValue($num);
    echo $num; // Output: 10
                

Function Scope in PHP

What is Function Scope in PHP?

Function scope рдпрд╣ рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░рддрд╛ рд╣реИ рдХрд┐ function рдХреЗ рднреАрддрд░ рдШреЛрд╖рд┐рдд variables рдХрд╣рд╛рдВ рддрдХ available рд╣реЛрдВрдЧреЗред PHP рдореЗрдВ, function scope рджреЛ рдкреНрд░рдХрд╛рд░ рдХреЗ рд╣реЛрддреЗ рд╣реИрдВ:

Types of Scope

  • Local Scope: Local scope рдореЗрдВ рд╡реЛ variables рдЖрддреЗ рд╣реИрдВ рдЬреЛ function рдХреЗ рдЕрдВрджрд░ declare рд╣реЛрддреЗ рд╣реИрдВред рдпреЗ variables function рдХреЗ рдмрд╛рд╣рд░ accessible рдирд╣реАрдВ рд╣реЛрддреЗред
  • 
    function test() {
        $a = 5;
        echo $a; // Output: 5
    }
    test();
    // $a cannot be accessed here, as it's local to the function.
                
  • Global Scope: Global scope рдореЗрдВ рд╡реЛ variables рдЖрддреЗ рд╣реИрдВ рдЬреЛ function рдХреЗ рдмрд╛рд╣рд░ declare рд╣реЛрддреЗ рд╣реИрдВред рдЗрди variables рдХреЛ function рдХреЗ рдЕрдВрджрд░ access рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╣рдореЗрдВ global keyword рдХрд╛ use рдХрд░рдирд╛ рдкрдбрд╝рддрд╛ рд╣реИред
  • 
    $a = 5;
    function test() {
        global $a;
        echo $a; // Output: 5
    }
    test();
                
  • Static Variables: Static variables рдЙрди variables рдХреЛ рдХрд╣рддреЗ рд╣реИрдВ рдЬреЛ function рдХреЗ рдЕрдВрджрд░ declared рд╣реЛрддреЗ рд╣реИрдВ, рд▓реЗрдХрд┐рди function рдХреЗ call рд╣реЛрдиреЗ рдХреЗ рдмрд╛рдж рднреА рдЙрдирдХрд╛ value retain рд░рд╣рддреЗ рд╣реИрдВред
  • 
    function counter() {
        static $count = 0;
        $count++;
        echo $count;
    }
    counter(); // Output: 1
    counter(); // Output: 2
                
h2 h3

FAQs

PHP рдореЗрдВ function рдПрдХ block рд╣реЛрддрд╛ рд╣реИ рдЬреЛ reusable code рдХрд╛ рд╣рд┐рд╕реНрд╕рд╛ рд╣реЛрддрд╛ рд╣реИред рдЗрд╕реЗ рд╣рдо рдХрд┐рд╕реА specific task рдХреЗ рд▓рд┐рдП рдмрдирд╛рддреЗ рд╣реИрдВ рдФрд░ рдлрд┐рд░ рдЗрд╕реЗ рдмрд╛рд░-рдмрд╛рд░ use рдХрд░рддреЗ рд╣реИрдВред PHP рдореЗрдВ function рдХреЛ define рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП function keyword рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

PHP рдореЗрдВ function рдХреЛ arguments pass рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, function call рдХрд░рддреЗ рд╕рдордп values рдХреЛ parentheses рдореЗрдВ рдбрд╛рд▓рддреЗ рд╣реИрдВред рдЖрдк arguments рдХреЛ value рдХреЗ рд░реВрдк рдореЗрдВ рдпрд╛ reference рдХреЗ рд░реВрдк рдореЗрдВ pass рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред Reference pass рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП, argument рдХреЗ рдкрд╣рд▓реЗ & symbol рдХрд╛ use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

PHP рдореЗрдВ function рдХрд╛ scope рдпрд╣ рддрдп рдХрд░рддрд╛ рд╣реИ рдХрд┐ рдЙрд╕ function рдХреЗ рдЕрдВрджрд░ declare рдХрд┐рдП рдЧрдП variables рдХрд╣рд╛рдБ рддрдХ accessible рд╣реЛрдВрдЧреЗред Local scope рдореЗрдВ variables рдХреЗрд╡рд▓ function рдХреЗ рдЕрдВрджрд░ accessible рд╣реЛрддреЗ рд╣реИрдВ, рдЬрдмрдХрд┐ global scope рдореЗрдВ variables function рдХреЗ рдмрд╛рд╣рд░ рднреА accessible рд╣реЛрддреЗ рд╣реИрдВред

PHP рдореЗрдВ default parameter рд╡рд╣ рд╣реЛрддрд╛ рд╣реИ, рдЬрд┐рд╕реЗ function definition рдореЗрдВ рдПрдХ default value рджреА рдЬрд╛рддреА рд╣реИред рдЕрдЧрд░ function рдХреЛ call рдХрд░рддреЗ рд╕рдордп рдХреЛрдИ value рдирд╣реАрдВ рджреА рдЬрд╛рддреА, рддреЛ рд╡рд╣ default value use рд╣реЛрддреА рд╣реИред

Passing by value рдореЗрдВ, function рдХреЛ рджрд┐рдП рдЧрдП arguments рдХреА values function рдХреЗ рдЕрдВрджрд░ modify рдирд╣реАрдВ рд╣реЛрддреАред Passing by reference рдореЗрдВ, function рдореЗрдВ рджрд┐рдП рдЧрдП arguments directly modify рд╣реЛрддреЗ рд╣реИрдВ рдФрд░ changes function рдХреЗ рдмрд╛рд╣рд░ reflect рд╣реЛрддреЗ рд╣реИрдВред

PHP рдореЗрдВ static variables рд╡рд╣ рд╣реЛрддреЗ рд╣реИрдВ рдЬреЛ function рдХреЗ рдЕрдВрджрд░ declare рд╣реЛрддреЗ рд╣реИрдВ, рд▓реЗрдХрд┐рди function рдХреЗ call рд╣реЛрдиреЗ рдХреЗ рдмрд╛рдж рднреА рдЙрдирдХрд╛ value retain рд░рд╣рддреЗ рд╣реИрдВред Static variable рдХреА value рдмрд╛рд░-рдмрд╛рд░ function рдХреЗ call рдкрд░ рдмрджрд▓рддреА рдирд╣реАрдВ рд╣реИред

Please Give Us Feedback