Function with Argument
×
Home Courses Community Support
Function with Argument

You can pass your own parameters inside a function. These parameters called arguments which are used to pass the information with in the function. To do so, you need to pass comma separated arguments inside the parenthesses OR you can use only one argument.

Let's see an example with single argument-

<?php
function android_version($version) {
    echo "Android Version $version.<br>";
}

android_version("Kitkat");
android_version("Lolipop");
android_version("Marshmallow");
?>

Output:

Android Version Kitkat.
Android Version Lolipop.
Android Version Marshmallow.

 

Example with double argument i.e. I will print my Name and Birthday.

<?php
function Name_Birth($Name, $Birth) {
    echo "My name is $Name and I was born on $Birth.<br>";
}
Name_Birth("Anuj Kumar Saini", "February 23, 1988");
?>

Output:

My name is Anuj Kumar Saini and I was born on February 23, 1988.

 

We can set a default value which called when there is no variable passed in function.

See below code-

<?php
function Name_Birth($Name = "Monu", $Birth = "August 13, 1992") {
    echo "My name is $Name and I was born on $Birth.<br>";
}
Name_Birth();
?>

Output:

My name is Monu and I was born on August 13, 1992.

 

 

← Preview

User Defined Function

Next →

Passing Argument by Refrence

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App