ကဗ်ာ/ရသ/နည္းပညာ

Variable In PHP

Dec 28, 2011
ကၽြန္ေတာ္တို႕ေက်ာင္းတုန္းက မသိကိန္းပုစၦာေလးေတြေရးဖူးတာ သတိရမယ္ထင္ပါတယ္ ။
ခရီးအကြာအေ၀း x ေပျဖစ္ပါေစတို႕ဘာတို႕ေလ ။ တကယ္ေတာ့ x ဆိုတာၾကိဳတင္သတ္မွတ္
လိုက္တာပါ ။ ဘယ္ႏွေပ လည္းမသိေသးလို႕ ေလာေလာဆယ္သတ္မွတ္ထားတာပါ ။
ေျပာရရင္ လူမလာေသးခင္ အခန္းၾကိဳငွားထားသလိုေပါ့ေနာ္ ။ Programming မွာလည္း အဲဒီလို
မသိကိန္းေလးေတြကုိအသံုးျပဳရပါတယ္ ။Variables လို႕သတ္မွတ္ပါတယ္ ။
ဘယ္လိုေနရာေတြမွာသံုးလည္းဆိုတာကေတာ့ေနာက္ပိုင္းဆက္ၾကည့္ေပါ့ေနာ္ ။

PHP မွာ Variable Type 8 မ်ိဳးကုိ Support လုပ္ပါတယ္ ။
၁။ Integers: (ကိန္းဂဏန္း) Are whole numbers, without a decimal point, like 4195
၂။ Doubles: (ဒသမကိန္း)Are floating-point numbers, like 3.14159 or.49.1
၃။ Booleans: (မွန္/မွား)have only two possible values either true or false
၄။ NULL:  (မွန္တာလည္မဟုတ္/မွားတာလည္းမဟုတ္ )Special Data Type (An uninitialized variable)
၅။ Strings:(စာသားေတြ) (‘’, ””, here documents (allows strings are multiple lines))
၆။ Arrays: (ေျပာရရင္အခန္းေလးေတြဖြဲ႕တာနဲ႕တူတယ္)similar to dictionaries in Python and hashes in Perl
   (It provides key/value Pairs)
၇။ Objects: are instances of programmer-defined classes, which can package up both other kinds of
values and functions that are specific to the class.
၈။ Resources: Special Data Type (Reference to a third party resource)

ဘယ္လိုသံုးသလဲ နည္းနည္းစမ္းၾကည့္ရေအာင္။
 PHP မွာ Variable ေၾကျငာရင္ $သေကၤတေလးကုိသံဳးပါတယ္ ။

ဥပမာ-
<?php
$txt="Hello!, How do yo do."
echo $txt;
?>

အေပၚကဥပမာေလးကုိၾကည့္ရင္ နားလည္မယ္ထင္ပါတယ္။
txt ဆိုတဲ့ variable ေလးထဲကို String အမ်ိဳးအစားေဒတာ "Hello!, How do yo do."
ထည့္လိုက္ေတာ့ txtကို ျပန္ထုတ္ျပခိုင္းတဲ့အခါ ေစာေစာကစာကုိOut put ထုတ္ျပပါတယ္ ။
PHP မွာ String ႏွစ္္ခုကုိ ဆက္သြယ္ခ်င္တယ္ဆုိရင္ ( . ) Operator ကုိ သံုးပါတယ္။
ဥပမာ-
<?php
$a="Hello,";
$b="Friends";
echo $txt1.$txt2;
?>
ဒါဆိုရင္ေတာ့
Hello,Friends ဆိုၿပီး Output ထုတ္ၿပပါမယ္ ။
Php ကုိ Html tag ေတြေရာၿပီးလည္းအသံုးျပဳႏိုင္ပါတယ္ ။
Html tag ေတြကုိ "" ထဲထည့္ေရးရပါတယ္ ။
ဥပမာ-
<?php
echo "<h1><font color='red'>";
echo "Hello!This is a new test php!";
echo "</font></h1>";
?>
ဒါဆိုရင္ေတာ့ Out put မွာ အနီေရာင္ေလးပါလာပါလိမ့္မယ္။စာလံုးလည္းၾကီးသြားတာေတြ႕ရပါမယ္။
ေနာက္ထပ္ Variable အသံုးျပဳပံုေလးေတြဆက္ေလ့လာရေအာင္ပါ။အခု number data ေတြကို
ေပါင္းႏွဳတ္ေျမွာက္စားလုပ္ၾကည့္မယ္ ။
Variable ၂ ခုကို ေပါင္းတဲ့အခါမွာ ( ) ထဲမွာေရးရပါတယ္။
ေပါင္းမယ္ဆိုလွ်င္ + အသံုးျပဳရမွာ ျဖစ္ၿပီး ႏႈတ္မယ္ဆိုလွ်င္ - , ေျမွာက္မယ္ဆိုလွ်င္ * , စားမယ္ဆိုလွ်င္ /
, ရာခိုင္ႏႈန္းလိုခ်င္ရင္ % ကို အသံုးျပဳရမွာျဖစ္ပါတယ္။ ဒီသေကၤတေတြကုိ Arithmatic Operators လို႕သတ္မွတ္ပါတယ္။
Arithmatic Operators မွာ အေရးၾကီးဆံုးႏွစ္ခုကေတာ့ ++ ႏွင့္ - - ျဖစ္ပါတယ္။ ++ က Increment  ျဖစ္ပါတယ္။
- -  ကေတာ့ Decrement ျဖစ္ပါတယ္။ 1++ လို႕ေရးျခင္းဟာ 1ၿပီးရင္ 2 ၿပီးရင္ 3 အစရွိသျဖင့္တိုးသြားမယ္လို႕ဆိုလိုတာ
ျဖစ္ပါတယ္။
ဒါဆို ဂဏန္းႏွစ္ခုကုိေပါင္းခိုင္းမယ္ႏွဳတ္ခိုင္းမယ္ ။စမ္းၾကည့္ရေအာင္။
ဥပမာ-
<?php
$a = 10000;
$b = 554.77;
echo ($a+$b);
?>
ကဲေနာက္တစ္ခါ ႏွဳတ္ခိုင္း ၊ေျမွာက္ခိုင္း ၊စားခိုင္းၾကည့္ပါဦး ..
ကုိယ့္ဖာသာဆက္စမ္းၾကည့္ေတာ့ေနာ္။
ဒါဆိုေနာက္တစ္ခု Comparison Operators ေတြကုိရွင္းျပပါမယ္ ။
Comparison Operator ဆိုတာကေတာ့ statement ေတြကို condition စစ္တဲ့အခါမ်ိဳးနဲ႔ loop လုပ္တဲ့အခါမ်ိဳးမွာသုံးပါတယ္။
==  is equal to
!=  is not equal
< >  is not equal
> =  Greater than or equal to
< = Less than or equal to
> Greater  than
ဥပမာ
x==12 ဆိုရင္ x ဟာ 12 နဲ႕ညီခဲ့ရင္လို႕ အဓိပၸါယ္ရပါတယ္။
x>12  ဆိုရင္ x ဟာ 12ထက္ႀကီးခဲ့ရင္လို႕ အဓိပၸါယ္ရပါတယ္။
x!=12 ဆိုရင္ x ဟာ 12 နဲ႕မညီခဲ့ရင္(မဟုတ္ရင္)လို႕ အဓိပၸါယ္ရပါတယ္။
အခုရွင္းျပခဲ့တဲ့ Operator ေတြအားလံုးဟာအလြတ္မွတ္မိေနရမယ့္ Operator ေတြပဲျဖစ္ပါတယ္ ။
ဒါေလးေတြကုိပဲအရင္အလြတ္က်က္ထားလိုက္ပါဦး ။
ေနာက္မွထပ္ဆက္ပါမယ္ ။

No comments:

Post a Comment