Please note, this is a STATIC archive of website technosmarter.com from July 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
 

Function Without arguments | No parameters


What is the meaning of function without arguments

Functions are used to create the functionality of tasks. To complete any task, you can create own functions. Creating a function is very easy. Some functions have already been made, such a function is called the built-in functions. You can also use the built-in function without having to pass parameters. The function without arguments means that you do not pass any arguments in the function. In the previous tutorials, we discussed function with arguments. In the function with arguments, we can pass the arguments as value or pass arguments as reference.

Function without parameters in PHP

As we discussed above, the function without parameters does not contain any variables as arguments. The normal function is known as function without parameter. i.e

 
function functionname()
{
block of code
} 

We can define all of the variables inside the function block.

The difference between the function with arguments and no arguments with function is minor. In function with arguments, we define the value at the time of function call and In without argument with functions we define value first and call the function.No arguments to pass in the function.

Example of function without arguments

In the below example, we create a function without passing parameters. In the block of function, we define the values of variables. Here, We do not need to give any arguments value at function calling time.

Example

<?php
function sum()
{
	$no=20+20;
	echo  $no;
}

sum();
?>

Run

Compare with function with arguments

You can create the same example using arguments. In this example, we pass two parameters in the function. Create functionality inside the block of code. At the time of calling a function, we specify the values of the arguments. It produces the same output.

Example with arguments

<?php
function sum($no1,$no2)
{
	$no=$no1+$no2;
	echo  $no;
}

sum(20,20);
?>

Output

 
40

There is a small difference between a function with arguments and function without arguments.

Built-In Functions


Please Share

Recommended Posts:-