PHP සිංහලෙන් - XIII

PHP සිංහලෙන් - XIII

PHP Function

function එකක් යනු කිසියම් කේත කොටසකින් ලබාගන්නා ආදානයකට අනුකූල වටිනාකමක් සකස් කර ලබාදීමයි.



* function එකක් තර්ක (arguments) එකක් හෝ කිහිපයක් පිළිගනී.
* function එකකට වැඩසටහනක් හැකි තරම් ප්‍රමාණයක් ඇමතීමේ හැකියාව ඇත.
* function එකකට නැවත අගයක් යැවීමේ හැකියාව ඇත.
* functions නැවත නැවත භාවිතා කිරීමේ හැකියාව තිබේ.
* functions වලට කේතයන් වල වැරදි සිදුවීම අවම කල හැකිය.
* functions වලට ඔබේ විශාල කේත කොටස් කෙටි කිරීමේ හැකියාව ඇත.

functions ආකාර දෙකකි.

1.User define function - කිසියම් කාර්යයක් සිදුකිරීමට වැඩසටහන්කරණ ශිල්පියා විසින් නිර්මාණය කරනු ලබන functions, User define functions ලෙස හැඳින්වේ.

උදාහරණය -

<?php
function firstfun()
{
echo "Hello !". "<br>";
echo date("Y/m/d") . "<br>";
echo " Welcome to the function "."<br>";
}
firstfun();//calling of function
firstfun();
firstfun();
?>

ප්‍රතිදානය -

Hello !
2017/03/02
Welcome to the function
Hello !
2017/03/02
Welcome to the function
Hello !
2017/03/02
Welcome to the function

2.Pre-define function - PHP භාෂාව විසින්ම නිර්මාණය කරන ලද functions, Pre-define functions ලෙස හැඳින්වේ.

උදාහරණය -

<?php
echo "sqrt of 16: is - "
print(sqrt(16) . "<br>");
echo "sqrt of 7: is -"
print(sqrt(7) . "<br>");
echo "sqrt of 36: is - "
print(sqrt(36) . "<br>");
echo "sqrt of 0.64: is -"
print(sqrt(0.64) . "<br>");
?>

ප්‍රතිදානය -

sqrt of 16: is - 4
sqrt of 7: is -2.6457513110646
sqrt of 36: is - 6


sqrt of 0.64: is -0.8

Related Articles

  • English Tutorials2016-07-12PHP Conditional Statements Conditional Statements Need to take different actions for different decisions… Read More
  • English Tutorials2016-07-12PHP Scope of Variables•The scope of a variable is the range of statements in which the variable can be… Read More
  • English Tutorials2016-07-12PHP Functions# Functions Will make your code easy to read and reuse. # Large projects wo… Read More
  • English Tutorials2016-07-12PHP LoopsWhen you need the same block of code to be executed over and over again . In P… Read More
  • English Tutorials2016-07-12PHP Variables Rules for PHP variables: 1. A variable starts with the $ sign, followed by the… Read More
  • English Tutorials2016-07-12FUNDAMENTALS of PHP Coding PHP Scripts You can use any text editor to create PHP scripts. PHP scr… Read More