Hướng dẫn dùng means hindi trong PHP

Learn PHP

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

Start learning PHP now »


Easy Learning with "PHP Tryit"

With our online "PHP Tryit" editor, you can edit the PHP code, and click on a button to view the result.

Example



echo "My first PHP script!";
?>


Try it Yourself »

Click on the "Try it Yourself" button to see how it works.


PHP Exercises



PHP Examples

Learn by examples! This tutorial supplements all explanations with clarifying examples.

See All PHP Examples


PHP Quiz Test

Learn by taking a quiz! This quiz will give you a signal of how much you know, or do not know, about PHP.

Start PHP Quiz!


My Learning

Track your progress with the free "My Learning" program here at W3Schools.

Log into your account, and start earning points!

This is an optional feature, you can study W3Schools without using My Learning.

Hướng dẫn dùng means hindi trong PHP


PHP References

W3Schools' PHP reference contains different categories of all PHP functions, keywords and constants, along with examples.


Kickstart your career

Get certified by completing the course

Get certified

w3schoolsCERTIFIED.2022



PHP मे Function का उपयोग Code के Reduplication को कम करने के लिए किया जाता है. Function के उपयोग से Code की Clarity मे सुधार किया जाता है Function सरल Pieces मे Complex Problems को भी कम कर देता है.

Nội dung chính

  • Functions With Parameters
  • For Example
  • Passing Arguments by Reference
  • For Example
  • Dynamic Function
  • For Example
  • Function Returning Value
  • For Example
  • PHP Function Syntax
  • PHP Function Example
  • PHP Function : Important Tips
  • PHP Function Advantages
  • PHP Types Of Function

Function Statement का एक Section होता है जिसका उपयोग किसी कार्यक्रम में बार-बार किया जा सकता है. यह Page के Load होने पर तत्काल Execute नहीं होता है इसे Function पर Call करके Execute किया जाता है.

Function Code का एक Piece है जो Parameter के रूप में Input लेता है और Processing के बाद एक Value Return देता है. PHP मे Function अन्य Programming Language के कार्यों के समान होती है. इसको Declare करने के लिए Function Keywords की आवश्यकता होती है.

Function को Body मे Define या Execute किया जाता है जो Curly Bracket के बीच मे होता है.

PHP Language में हजारों built-in Functions हैं.

Functions With Parameters

PHP आपको एक functions के अंदर अपने Parameters को पास करने का विकल्प देता है जिससे आप ज्यादा Parameters को पास कर सकते है.

For Example


   
   
      Function with Parameters Example
      
   
         
            
   


Output

Total of the two numbers is : 95

Passing Arguments by Reference

Functions को Reference द्वारा Arguments भेजना संभव है. इसका मतलब है कि Variable के Reference में Functions के द्वारा Variable की Value को कापी के बजाय हेरफेर किया जाता है.

For Example


   
   
      Passing Arguments by Reference Example
      
        
      ";
 
         changeValue( $original );
         
         echo "Changed Original Value is $original 
"; ?>

Output

Original Value is 30
Changed Original Value is 25

Dynamic Function

Function के नाम को Variables के रूप में Assign करना मुमकिन है और फिर इन Variables को उसी तरह से व्यवहार करना चाहिए जैसा आप Function नाम ही करेंगे.

For Example


   
   
      Dynamic Function Example
      
        
           
    


Output

You are calling printText function dynamically.

Function Returning Value

एक Function Value या Object के साथ संयोजन के साथ Return Statement का उपयोग करके एक Value को वापस कर सकता है. Return Function के निष्पादन को बंद कर देता है और Value वापस कॉलिंग कोड को भेजता है.

For Example


   
   
      Function Returning Value Example
      
         
            
   


Output

Total of the two numbers is : 77



PHP Articles in Hindi

Function reusable piece of code या block of code होता है जो कि कोई specific task perform करता है।  एक बार  define करने के बाद हम इन्हें  कितनी ही बार use कर सकते हैं।  PHP में 1000+ predefined useful function हैं जिन्हें  हम Built In Functions कहते  हैं।     

हालाँकि PHP हमें ये facility provide करती है कि user खुद के function define कर सके जिनहे User Defines Functions कहते हैं । Web page load होते समय कोई भी  function automatically run नहीं होता है जब तक कि हम उसे call न करें।

PHP Function Syntax

function function_name()
{
  //perform task here
  return something /*it's optional*/
}

Function में return statement optional होता है , आप चाहे तो कोई value या statement return करा सकते हैं।

PHP Function Example

File : function.php

Output

Hell ! this is my first user defined function.


PHP Function : Important Tips

1. आप एक ही name के function define नहीं कर सकते , अगर आप ऐसा करते हैं तो PHP Fatal Error Generate कर देगी।

2. PHP में Functions नाम ASCII characters A to Z के लिए case insensitive होते हैं , means myfun() define किये जाने के बाद इसे आप Myfun() या MYFUN() name से भी call करा सकते हैं।

Note - PHP में functions और methods दोनों अलग - अलग हैं -

Methods  किसी Class   के अंदर define  किये जाते हैं इन्हे हमेशा Class Name या Class Object के साथ access किया जाता है हालाँकि यह method के type पर depend करता है , अगर method static हुआ तो Class Name  के साथ access किया जायेगा और अगर non-static हुआ तो Class Object के साथ   access किया जायेगा।

जबकि function out of the class define किया जाते है , ये Class / Object के context में नहीं होते इसलिए इन्हें कहीं भी access  किया जा सकता है , class के अंदर   भी  और  class के बाहर भी।

PHP Function Advantages

1.  Code Re-usability  :  functions use करने का  सबसे बड़ा advantage यही है कि , हम code को reuse कर सकते हैं।  same processing के लिए एक बार function define  करने के बाद उसे हम कही भी और कितनी बार भी use कर सकते हैं। 

2. Less Code  :  चूंकि हम same code के लिए functions  use करते हैं  जिससे Program की length कम जाती  है।

3. Reduce Coding Time : Function use करने से  coding time reduce होता है , जो कि किसी भी developer के लिए important है।

4. Easy To Understand  :  Code को समझना आसान हो जाता है।

5. Easy To Maintain :  समय के साथ - साथ हमें code update करना पड़  जाता है जिसे हम function की help से आसानी से maintain कर सकते हैं।

PHP Types Of Function

PHP में हम लगभग 7 type के functions use करते हैं।

  1. Returning Values
  2. Parameterized Functions
  3. Call By Value and Call By Reference
  4. Variable Length Argument Functions 
  5. Recursive Functions
  6. Anonymous Functions
  7. Arrow Functions