Tuesday, 9 June 2020

php variables and strings

lesson 4
A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).
Rules for PHP variables:
A variable starts with the $ sign, followed by the name of the variable
A variable name must start with a letter or the underscore character
A variable name cannot start with a number
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive ($age and $AGE are two different variables)
<?php
if(1==2){
echo 'true';
else {
echo 'false';
}
?>
<?php
$x= 1;
if($x == 1) {
echo 'correct'; }
else {
echo 'incorrect';
}
?>
IF STATEMENTS USED TO COMPARE TWO STRINGS
<?PHP
$name= "vamsi";
if ($name="vamsi") {
echo 'its is correct';
} else(
echo 'you cant enter';
}
?>
<?php
$un = 'user';
$pw = 'password';
in this two if , if ist true then checked fro next if , so it called as nestedif
if  ($un == 'user') {
ist it checks the un comparision, if it is true
if ($pw == 'password') {
then it go to check this pw, if this also
echo 'you can enter';
true,then it prints this,if password is wrong
}
it print this invalid password
else{
echo 'invalid password';
nested if means ist conditon must be true then it goes to next if
}
else{
echo 'you cannot enter';
}
?>
if ($un == 'user' && $pw == 'password')
using this it checks and condition, both can true then only it executes this

if ($un == 'user' || $pw == 'password')
if any one is true, it will executes, or conditoin
$age = 40;
based on the enter value, it checks the conditon
if ($age <20){
simply like or
echo 'you are a teenager';
if else if is if ist conditon is not true, then it checks for another else if
} else if ($age >= 20 && $age< 40){
echo 'you are a young';
} else if ($age >= 40 && $age< 60){
echo 'you are old';
} else{
echo 'you are too old';
}
?>
if else statements
if else
if if else
logical operators
logical operators
if elseif elseif else

how to compare two numbers,if false execute on thing
how to compare the number with another rnumber via variable
how to compare two strings
how to check given value and execute one statement 
how to check more than conditons
how to check moer than two conditons in one statement
how to check more than one conditon
how to execute if given statement is this , execute this

No comments:

Post a Comment