Pages

Friday 7 September 2012

Php အေျခခံ-4

Comparison Operators
Operator
Description
Example
==
is equal to
5==8 returns false
!=
is not equal
5!=8 returns true
<>
is not equal
5<>8 returns true
>
is greater than
5>8 returns false
<
is less than
5<8 returns true
>=
is greater than or equal to
5>=8 returns
<=

false
is less than or equal to
5<=8 returns true


Comparison operator ေတြကို variable ေတြရဲ့ value ေတြတခုနဲ႔တခုကို ႏွိဳင္းယွဥ္လိုတဲ႔အခါမွာအ သံုးၿပဳရမွာ ၿဖစ္ပါတယ္။က်ေနာ္တခုစီရွင္းပါ့မယ္။



== operator
=operator နဲ႔ မတူဘူးဆိုတာသတိၿပဳၾကပါ။= operator က တန္ဖိုးသတ္မွတ္ဖို႔ပါ။အခုဟာက  ႏွိဳင္းယွဥ္ဖို႔ပါ။က်ေနာ္ ဥပမာၿပပါ့မယ္။
X=5 ဆိုရင္ ဆိုလိုတာက xမွာ 5 ဆိုတဲ့ တန္ဖိုးရွိတယ္လို႔ေၿပာတာေနာ္။xဟာ 5 နဲ႔ တူတယ္လို႔ေၿပာတာ မဟုတ္ဘူး။ x ဆိုတာက text ၊ 5 ဆိုတာက number ၊ မတူပါဘူး။
== operator ကို ဘယ္လိုေနရာမွာသံုးမလဲဆိုေတာ့ conditional statement ေတြမွာသံုးရပါတယ္။ conditional statement ေတြကိုေတာ့ က်ေနာ္ သူတို႔အခန္းေရာက္မွ အေသးစိတ္ရွင္းၿပမွာပါ။အခု အဓိပၸါယ္ သိလိုရင္ေတာ့ condition ဆိုတာ အေၿခအေနတခုအတြင္းက မတူတဲ့လုပ္ေဆာင္ခ်က္ေတြ ပါပဲ။
က်ေနာ္တို႔ website တခုကို username,password နဲ႔ login ဝင္တဲ့အခါ username နဲ႔ password မွန္ေနရင္ site ထဲကိုဝင္ခြင့္ရမယ္။မမွန္ရင္ ဝင္လို႔မရဘူး ။အဲလိုအေၿခအေနဟာ conditional statement ပါပဲ။ ဒီဟာၿဖစ္ရင္ ဒါလုပ္မယ္ဆိုတဲ႔သေဘာပါပဲ။
အဲဒီမွာ ဘယ္လိုသတ္မွတ္ထားလဲဆိုေတာ့ username== “moeaye” , password==123  ဒါကိုဘာသာၿပန္ရရင္ username ဟာ moeaye ဆိုတဲ့ value ၿဖစ္ၿပီး password ဟာ 123 ၿဖစ္တယ္ဆိုရင္ ဝင္ခြင့္ၿပဳတယ္ေပါ့ ။ မဟုတ္ရင္ေတာ့ မဝင္ရဘူးေပါ့။ user inputကေနၿပီးရိုက္လိုက္ တဲ့တန္ဖိုးေတြဟာ moeaye နဲ႔ 123 ၿဖစ္မွ site ထဲကိုဝင္ခြင့္ရမွာပါ။ ဒါကေတာ့ == operator ရဲ့သေဘာပါပဲ။username ဟာ moeaye ၿဖစ္တယ္လို႔သတ္မွတ္ထားတာမဟုတ္ဘူး။ username ဟာ moeaye နဲ႔ ထပ္တူၿဖစ္တယ္လို႔သတ္မွတ္ထားတာၿဖစ္ပါတယ္။
!= operator ကေတာ့ == နဲ႔ေၿပာင္းၿပန္ပါ။ မညီဘူးလို႔အဓိပၸါယ္ရပါတယ္။ not equal ေပါ့။ သူ႔ကို ေနာက္တမ်ိဳးဒီလိုသံုးပါတယ္။ <> ပါ ။ $x<>5 ဆိုရင္ $x ဟာ 5 မဟုတ္ဘူးလို႔ ဆိုလိုတာပါ။!= နဲ႔ တူတူပါပဲ။
> operator ကေတာ့ ၾကီးၿခင္းကို ႏွိဳင္းယွဥ္ဖို႔ အတြက္ပါ။ $x>10 ဆိုရင္ $xဟာ 10 ထက္ၾကီးတယ္ လို႔ဆိုလိုတာပါ။
< operator ကေတာ့ ငယ္ၿခင္းကို ႏွိဳင္းယွဥ္ဖို႔ အတြက္ပါ။$x<10 ဆိုရင္ $xဟာ 10ထက္ငယ္တယ္လို႔ ဆိုလိုတာပါ။
>= operator ကေတာ့ ၾကီးမယ္၊ဒါမွမဟုတ္ ညီမယ္လို႔ အဓိပၸါယ္ရပါတယ္။$x>=10 ဆိုရင္ $x ဟာ 10ထက္ၾကီးမယ္(သို႔) 10 နဲ႔ ညီတယ္လို႔ဆိုလိုတာပါ။
<= operator ကေတာ့ ငယ္မယ္၊ဒါမွမဟုတ္ ညီမယ္လို႔ အဓိပၸါယ္ရပါတယ္။$x<=10 ဆိုရင္ $xဟာ  10ထက္ငယ္မယ္(သို႕) 10 နဲ႔ညီတယ္လို႔ဆိုလိုတာပါ။
ဒီ operator ေတြကို ဒီေနရာမွာ က်ေနာ္ နမူနာေတြ မၿပေတာ့ပါဘူး။ သခ်ၤာ အေၿခခံသေဘာတရား ေတြၿဖစ္တဲ့အတြက္ အားလံုးရင္းႏွီးၿပီးသားၿဖစ္မယ္လို႔ထင္ပါတယ္။ေနာက္ၿပီး condition statement အခန္းမွာ ဥပမာ မ်ားစြာေတြ႔ရမွာၿဖစ္တဲ့အတြက္ အခုအခန္းမွာေတာ့ မွတ္မိေအာင္ေလ့လာထားဖို႔ပဲလို ပါတယ္။

Logical Operators
Operator
Description
Example

&&
And
x=6  y=3(x < 10 && y > 1)returns true
||

or

x=6   y=3   (x==5 || y==5) returns false

!
not
x=6  y=3    !(x==y)    returns true

Logical operator ဆိုတာကလဲ အသံုးမ်ားတဲ့ Operator တခုပါပဲ။
&& operator
အဂၤလိပ္ အကၡရာ and ရဲ့ အဓိပၸါယ္ပါ။ အေၿခအေနႏွစ္ခုလံုး မွန္ေနတယ္ဆိုတဲ့ သေဘာပါ။
$x=5;
$y=6;
if($x>3 && $y<9)
{
Echo “this is right”;
}
အထက္က codeကိုၾကည့္ပါ။ $x ဟာ 3 ထက္ၾကီးၿပီး $y ဟာ 9 ထက္ငယ္ရင္  this is right ဆိုတဲ့ string ကို output ထုတ္ပါလို႔ code ေရးထားတာပါ။ အဲဒီမွာ အေၿခအေနႏွစ္ရပ္လံုးက မွန္ေနရမယ္။ တကယ္လို႔ $y ဟာ 9 ထက္ၾကီးေနရင္ အေၿခအေန တစ္ရပ္က မွားေနတဲ့အတြက္ output ထုတ္မွာမဟုတ္ပါဘူး။ဒါေၾကာင့္ && operator ကိုသံုးမယ္ဆိုရင္ condition ႏွစ္ရပ္လံုးမွန္ေနဖို႔လိုပါ တယ္။ if ဆိုတဲ့ condition statement ကိုေတာ့ ေနာက္သင္ခန္းစာေတြမွာေလ့လာရပါမယ္။
|| operator
အဂၤလိပ္ အကၡရာ or ရဲ့ အဓိပၸါယ္ပါ။ (သို႔မဟုတ္)လို႔အဓိပၸါယ္ရပါတယ္။ သူကေတာ့ condition ႏွစ္ခုအနက္မွာ တခုေတာ့မွန္ရပါမယ္။ ႏွစ္ခုလံုးမွန္ေနရင္လဲ ရပါတယ္။အနည္းဆံုးေတာ့ တခုမွန္ရပါမယ္။ႏွစ္ခုလံုးမွားေနလို႔ေတာ့ မရပါဘူး။
$x=5;
$y=6;
if($x>3 || $y>9)
{
Echo “this is right”;
}
အထက္က code မွာ $x>3 ဆိုတာမွန္ေနၿပီး $y>9 ဆိုတာက မွားေနပါတယ္။ ဒါေပမယ့္ condition တခု မွန္ေနတဲ့အတြက္ this is right ဆိုတာကို output ထုတ္ေပးပါလိမ့္မယ္။ ႏွစ္ခုလံုးမွားေနလို႔ေတာ့ မရပါဘူး။
! operator
သူကေတာ့ အဂၤလိပ္အကၡရာ not နဲ႔ အဓိပၸါယ္တူပါတယ္။
<?php
$x=6;
$y=5;
if(!($x==$y))
{
echo "this is right";
}
?>
အထက္က code အရဆိုရင္ $x နဲ႔ $y ရဲ့ တန္ဖိုးေတြဟာ တူေနတာ မဟုတ္ဘူးဆိုရင္ this is right ဆိုတဲ့ string ကို output ထုတ္ေပးပါလို႔ ဆိုလိုတာပါ။$x=6,$y=5 လို႔သတ္မွတ္ထားေတာ့ မတူဘူးေလ။ ဒါေၾကာင့္ output ထုတ္မွာၿဖစ္ပါတယ္။ သူကိုေတာ့ ဒါမဟုတ္ရင္ ဒီလိုလုပ္ပါ ဆိုတဲ့ condition အေၿခအေနေတြမွာသံုးရပါတယ္။ အသံုးမ်ားတဲ့ operator ပါပဲ။
concatenate operator
ေနာက္ဆံုး operator တခုကိုေၿပာပါ့မယ္။ concatenate operator ပါ ။ dot character ( . ) နဲ႔ သတ္မွတ္ထားပါတယ္။ သူကိုေတာ့ string ေတြ အခ်င္းခ်င္း ေပါင္းစပ္ဖို႔ တခုတည္းအတြက္ပဲ သံုးပါတယ္။
<?php
$x= “hello”;
$y= “I am webdeveloper”;
echo $x. “<br/>”.$y;
?>
ဒါဆိုရင္ output မွာ hello ၊ ေနာက္တစ္ေၾကာင္းက I am webdeveloper ဆိုၿပီးေတြ႔ရမွာပါ။$x နဲ႔ $y တို႔ရဲ့ string value ႏွစ္ခုကို concatenate လုပ္လိုက္တာပါပဲ။ ၾကားထဲက <br/> ဆိုတာကေတာ့ line break အတြက္ဆိုတာ သိမွာပါ။ဒီ operator ကိုေတာ့ string ေတြ အခ်င္းခ်င္း ေပါင္းစပ္ဖို႔အ တြက္ပဲ သံုးလို႔ရပါတယ္။
အခုဆိုရင္ေတာ့ operator ေတြအေၾကာင္းေလ့လာလို႔ၿပီးပါၿပီ။ အခုဆက္ၿပီး condition statement ဆိုတာ ဘာလဲဆိုတာ ဆက္ၿပီးေလ့လာၾကပါမယ္။

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

အေထြးေထြးနည္းပညာမ်ား