PHP Functions

  • The function defined by the user
  • built-in function
  • It enables top-down modular programming.
  • The program’s length has been shortened.
  • Once written, it can be used at any time.
  • Working with user-defined functions necessitates the usage of two key components.
function function_name([parameters]){Statements to be executed;[return value;]}
function_name([Parameters if Any]);Whenever you wish to run a specified function, you must call it with the appropriate arguments, and if the function returns a value, you must save the result. Let's have a look at a basic example.For Ex.<?phpfunction Display()//function Definition{echo "Hello DiscussDesk<br>";}Display();//function callDisplay();?>As you can see from the example, we first built a function named Display(), which accepts no parameters and has no return value. Later in our software, we invoked the Display() method twice, which executed the code twice.
Hello DiscussDeskHello DiscussDeskFunction returning valueTo return a value, add a return statement at the conclusion of the function body. The following is an example of this.For Ex.<?phpfunction sum($a,$b){$c=$a+$b;return $c;}echo "10 + 20 =".sum(10,20)."<br>";echo "10.30 + 20.30 =".sum(10.30,20.30)."<br>";?>Output10 + 20 = 3010.30 + 20.30 = 30.6So, to summarize, in this session, we learned what php function is. Also covered is how to use a user-defined function in PHP.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

DOCKER STORAGE WITH DATA VOLUMES

Stack Overflow Developers Salaries

Let’s Build our Shop

Automate Your Code Review

Adding Consistency and Automation to Grafana

How to Create a Virtual Machine Using vSphere Client 7.0

Test Doubles — Fakes, Mocks and Stubs.

Natural Join with NATURAL JOIN, ON, USING clause

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
sanjeev kumar

sanjeev kumar

More from Medium

Web server on windows for local development

How to Install PHP on Windows?

How to Install PHP on Windows?

How To Get All Dates Between Two Dates in PHP Tutorial

Get CRUD System with Live Input Data Validation using PHP with Free Source Code