This kind of simple if/then statement is very common in every day life.It also appears in programming quite very often.
The if statement is very important in PHP.
An if statement is a way of controlling the execution of a statement that follows it.
The if statement evaluates an expression and if the results in a true, the statement is executed. Otherwise, the statement is skipped entirely.
This enables scripts to make decisions based on any number of factors.
Let's look at the details of this example.
See what happens when a PHP if statement is not true,(false)
Here the variable contained the value "Sam", which is not equal to "Joe".
The if statement evaluated to false, so the code segment of the if statement was not executed.
When used properly, the if statement is very powerful.
သင္သည္အျပင္ထြက္၍တခုခုစားသည္ဆိုပါစို႔။ ေအာက္ပါ အတိုင္း ေတြးႏိုင္ ပါသည္။
အကယ္၍ ငါ့မွာ ေငြ မ်ားမ်ား ရွိရင္ ေဟာ္တယ္မွာ သြားစားမယ္၊ မဟုတ္ ပါက၊ လမ္းေဘး ဆိုင္မွာ သြားစားမယ္။
အကယ္၍ ဒါရွိရင္ ဒီလို လုပ္မည္၊ ဒါမရွိ ပါက၊ ဟိုလို လုပ္မည္ ဆိုေသာ လုပ္ေဆာင္ ခ်က္မ်ိဳးကို လူအမ်ား ေန႔စဥ္လို အၿမဲ လုပ္ေနၾက ပါသည္။ Programming ေလာက တြင္လည္း [အကယ္၍] if statement ကို အလြန္ အသံုး မ်ားပါသည္။
PHP တြင္ if statement သည္ အလြန္အေရး ပါပါသည္။
If statement ကိုအသံုး ခ်ၿပီး code မ်ား၏ လုပ္ေဆာင္ မွဳကို ထိန္းခ်ဳပ္ ႏိုင္ပါသည္။
If statement ျဖင့္ အေျခအေန တစ္ရပ္ မွန္မမွန္ ကို ဆန္းစစ္ ပါသည္၊ မွန္ေန ပါက code ကို လုပ္ေဆာင္ ေစၿပီး၊ မမွန္ ပါက၊ code လုပ္ေဆာင္ မွဳကို ရပ္ဆိုင္း လိုက္ပါသည္။
If statement ျဖင့္ ဆက္သြား ရမည့္ လမ္းကို ေရြးခ်ယ္ ေစပါသည္။
ဆန္းစစ္ၾကည့္ ၾကရေအာင္။
PHP if statement သည္ မမွန္ပဲ (false) ျဖစ္ခဲ့လ်င္ မည္သို႔ ျဖစ္သည္ကို ၾကည့္ၾက ပါစို႔။
ဤေနရာတြင္ $name="Sam" ဟု ပထမ code စာေၾကာင္း တြင္သတ္မွတ္ လိုက္ပါသည္။
If statement ျဖင့္ $name ကို Joe ဟုတ္မဟုတ္ ေၾကာင္း (false) ဟု ေတြ႔ရွိ ရသျဖင့္ { -- } ႏွစ္ခု အၾကားရွိ echo "Your name is Joe!<br />" ကိုလုပ္ေဆာင္ ျခင္းမျပဳပဲ ရပ္ဆိုင္း ထားခဲ့ သည္ကို ေတြ႔ရ ပါသည္။
PHP တြင္ if ststement သည္ အလြန္မွ အင္အား ႀကီးမား ပါသည္။