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

* function එකක් තර්ක (arguments) එකක් හෝ කිහිපයක් පිළිගනී.
* function එකකට වැඩසටහනක් හැකි තරම් ප්රමාණයක් ඇමතීමේ හැකියාව ඇත.
* function එකකට නැවත අගයක් යැවීමේ හැකියාව ඇත.
* functions නැවත නැවත භාවිතා කිරීමේ හැකියාව තිබේ.
* functions වලට කේතයන් වල වැරදි සිදුවීම අවම කල හැකිය.
* functions වලට ඔබේ විශාල කේත කොටස් කෙටි කිරීමේ හැකියාව ඇත.
functions ආකාර දෙකකි.
1.User define function - කිසියම් කාර්යයක් සිදුකිරීමට වැඩසටහන්කරණ ශිල්පියා විසින් නිර්මාණය කරනු ලබන functions, User define functions ලෙස හැඳින්වේ.
උදාහරණය -
<?phpfunction firstfun() {echo "Hello !". "<br>";echo date("Y/m/d") . "<br>";echo " Welcome to the function "."<br>";}firstfun();//calling of functionfirstfun();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 ලෙස හැඳින්වේ.
උදාහරණය -
<?phpecho "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

