
PHP Constant (PHP නියත ) -
PHP Constant යනු එක්තරා විදියක variable එකක් වන අතර එමඟින් කිසියම් එක් අගයක් පමණක් ඉදිරිපත් කෙරේ. එනම් කිසියම් එක් වටිනාකමක් (value) සඳහා නමක් හෝ හඳුන්වනයක් ලෙස PHP Constant හැඳින්විය හැකිය. සෑම විටම PHP Constant එකක් uppercase හෙවත් ලොකු අකුරු වලින් ලිවිය යුතු අතර මුල් කොටස සෑම විටම එක්කෝ අකුරක් හෝ underscore (_) එකක් විය යුතුය. variable එකක් මෙන් නොව PHP Constant $ සලකුණින් ආරම්භ විය යුතු නැත.
උදාහරණය -
<?php
define(
"str"
,
"This is a String Constant"
);
define(
"data"
, 38);
echo
str;
echo
'<br>'
;
echo
"this is integer constant:-"
;
echo
data;
echo
'<br>'
;
?>
ප්රතිදානය -
this is integer constant:-38
PHP Constant වල කලින් අර්ථවත් කල නියත (Pre-Define Constant) කිහිපයක් ඉදිරිපත් කර ඇත.
උදාහරණය -
<?php
echo
"line number of this lie: "
.
__LINE__
.
"<br>"
;
echo
"Name of this file: "
.
__FILE__
.
"<br>"
;
echo
"Directory of current file: "
. __DIR__.
"<br>"
;
echo
"Running system (o S): "
.PHP_OS.
"<br>"
;
echo
"Php version"
. PHP_VERSION.
"<br>"
;
?>
ප්රතිදානය -
Name of this file: /home/ptutorial3/public_html/php-tutorial/exmp/example-pre-define-constant.php
Directory of current file: /home/ptutorial3/public_html/php-tutorial/exmp
Running system (o S): Linux
Php version5.4.45