Hello! friends today exercise will be interesting as we are going to work on the fun part of php function, this will let us to declare and use function.
how to create your own php function, see code
function functionName(parameters)
{
statement;
}
simple right? sure
Now let create one and test it, open your code editor and copy the below code to your editor, save as function.php and run your localhost see result
function helloWorld()
{
$text="Hi! Hello World!";
return $text;
}
we have just created our php helloWorld function, this will not output anything untill we call that function, here is how
echo helloWorld();
This will now output the hello World message to the user
Other examples
function Add($num1,$num2)
{
$result=$num1+$num2;
return $result;
}
echo Add(10,23);
or
$num1=10;
$num2=23;
echo Add($num1,$num2);
if you don't understand about variable and datatype click here
how to create your own php function, see code
function functionName(parameters)
{
statement;
}
simple right? sure
Now let create one and test it, open your code editor and copy the below code to your editor, save as function.php and run your localhost see result
function helloWorld()
{
$text="Hi! Hello World!";
return $text;
}
we have just created our php helloWorld function, this will not output anything untill we call that function, here is how
echo helloWorld();
This will now output the hello World message to the user
Other examples
function Add($num1,$num2)
{
$result=$num1+$num2;
return $result;
}
echo Add(10,23);
or
$num1=10;
$num2=23;
echo Add($num1,$num2);
if you don't understand about variable and datatype click here
No comments:
Post a Comment