php development

// variable and constant is almost same but variable is changeable and constant unchangble

$variable =”variable and constant “;

$tag =”You Can use tag “;

echo “<h1>$tag</h1>”;

echo $variable;

define (“CONSTANT”, ” constant store”);

define (“AMAOUNT”, 100);

echo CONSTANT;

ECHO “<br>”;

ECHO AMAOUNT;

echo “for string and”. $variable;

// echo is fast and most use, but print is slow: you can use print funtion and get a 1 valu. but echo not used for function.

// data type

$string = “any word”;

$intiger = 20;

$floating = 10.5;

$boolean = true; //true or false

$null = “”; // null mean empty

var_dump ($string, $intiger, $boolean); // var_dump for code test, single or multy.

$name = “islami media”; // ucword for capitalize each word

$new_name = ucwords ($name);

echo “Hello $new_name”;

// frintf function

$my_name =”Sheikh”;

$my_adress = “Paikarhati”;

printf (“My name: %s My adress: %s”, $my_name, $my_adress); //%s (place Holder)

//arithmetic operator

$num = 4+6;

echo $num;

//assignment operator

// Increment (++) is return =1 And Decrement (–) Operators

$amount = 10;

$amount ++;

echo “<br>”;

echo $amount;

echo “<br>”;

// Concatenation used for pluse, example: fist name and last name.

$first_name = “Sheik”;

$last_name =”Rozob”;

$full_name = $first_name.” “.$last_name; // duble “” for space.

echo $full_name;

echo “<br>”;

/*comparison

$varl = 22;

$var2 = 20;

> — $varl > $var2 — false;

< — $varl < $var2 — true;

>= — $varl >= $var2 — true;

<= — $varl <= $var2 — true;

== — $varl == $var2 — false;

!= — $varl != $var2 — true;    (!=) not uqual

<> — $varl <> $var2 — true;

=== — $varl === $var2 — false; type and valu is same.

!== — $varl !== $var2 — false; type and valu is not same.

*/

$varl = 22;

$var2 = 20;

var_dump ($varl > $var2); // result: true =1, false = 0

echo “<br>”;

// If Else

$username = “sheik”;

if ($username == “sheikh”){

    echo “Login Successfull”;

} else { echo “Login Failed”;};

// intiger

$username = 500;

if ($username > 450 ){

    echo “Price is High”;

};

// else if

$month_name = “jan”;

if ($month_name == “jan”)

{ echo “January”;}

else if ($month_name ==”feb”)

{ echo “February”; }

else { echo “Nothin”;}; //end

echo “<br>”;

 //Ternary Operator (?:)

 $user = “”;

 $age = 25;

$user = ($age > 18) ? “admin” : “Guest”;

echo $user;

// Logical OR Operator

 $OROperator = “admin”;

 $editor = “edetor”;

 if ( ($OROperator == “admin”) || ($editor == “abcd”)  ) {

    echo “Or is ok”;

 }

 echo “<br>”;

 // Logical && Operator

 $admin = “User name”;

 $password = “12345678”;

 if ( ($admin == “User name”) && ($password == “12345678”)  ) {

    echo “Login Successfull (and (&&)”;

 }

 // Not Operator used form

$User_invelid = “januag”;

$user_length = strlen ($User_invelid);

if ( !($user_length >= 4 && $user_length <=12 ) ) {

    echo “Invalid Username”;}

    else {

        echo “Valid Username”; }

        //Nested If Operator

        $nested_user = “Usama”;

        $nespassword = “12345”;

        if ($nested_user == “Usama”)

            if ($nespassword == 1234) {

                echo “Hello User”;

            }

            else {

                echo “Invalid Password”;

            }

            else {

                echo “Invalid Username”;

            }

// While Loop for repeat on work for example : while () {}

 $loop =1;

 while ( $loop <= 5 ) {

    echo “Islam <br>”;

    $loop++;

 };

 // do loop

 $doloop = 1;

 do {

    echo $doloop . “<br>”;

    $doloop++;

 } while ($doloop <= 5);

// For Loop most usefull

for ($count = 1; $count <= 5; $count++) {

echo “Hello $count <br>”;

}

for ($count = 1; $count <= 5; $count+= 2) {

    echo “Hello $count <br>”;

    }

    ?>

Leave a Comment