Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

Tuesday, 25 February 2014

Comparison operators in Php

Comparison Operators php
This tutorial is about Comparison Operators.Now “Comparison Operator” is basically to compare one or more values. We can compare any amount of values in a single statement.In this tutorial we will compare three values via demonstration.Now for this example, we are going to use “if statement” , I had shown you example about If Statement in my previous tutorials .

code for if Statement Condition true (Screenshot1):-

comparison operators in php
Screenshot1
<?php
$number1 = 10;
$number2 = 9;
if (true) {
echo 'inside.';
}
?>

Output (Screenshot2) :-

if statement condition ture
Screenshot2
In this code, condition evaluates either true or false. If I write true it will execute it and inside the browser it will display it and if I will write false it will not execute inner side of “if statement” example.

code for if Statement Condition false (Screenshot3):-

comparison operators in php
Screenshot3
<?php
 
$number1 = 10;
$number2 = 9;

if (false) {

echo 'inside.';

}

?>

output (Screenshot4) :-

comparison operators in php
Screenshot4
In this code it automatically evaluates “False” by false keyword. Now its same as we do 1==1. It just contain “double equal to” sign to compare variables. Now always remember when we assign values we use single equal sign (=) and in comparison we use double equal to sign (==) for comparing two variables.

Code for comparison operators Example (Screenshot5):-

Comparison operators in php
Screenshot5
<?php
$number1 = 10;
$number2 = 9;
if (1==1) {
echo 'inside.';
}
?>

Output (Screenshot6):-

comparison operators in php
Screenshot6
In this example we are comparing variables such as number one is equal to number one, condition is true so,it will echo out the result as you seen in screenshot6.

Code for comparison operators Example (Screenshot7):-

Comparison Operators In php
Screenshot7
<?php
$number1 = 10;
$number2 = 9;
 
if (1==2) {
echo 'inside.';
}
?>

Output (Screenshot8):-

Comparison operators in php
Screenshot8

In this example number one is not equal to number two then it will evaluate false condition and will not echo out anything as result as u seen in (screenshot 8).
Other Comparison Operators Examples

Code for comparison operators Example (Screenshot9):-

comparison operators example
Screenshot9
<?php
$number1 = 10;
$number2 = 9;
if (1!=2) {
echo 'inside.';
}
?>

output (Screenshot10):-

comparison operators in php
Screenshot10
In this example we are using exclamation mark (!) which means not number one is not(!) equal to number two, then it evaluates true which will echo out as result.

Code for comparison operators Example (Screenshot11):-

comparison operators in php
Comparison Operators Screenshot11
<?php
$number1 = 10;
$number2 = 9;
if (1!=1) {
echo 'inside.';
}
?>

output (Screenshot12):-

comparison operators
Screenshot12
In this example we are using exclamation mark (!) which means not number one is not(!) equal to number one, then it evaluates false which will echo out as result.

Code for comparison operators Example (Screenshot13):-

comparison operators
Screenshot13
<?php
$number1 = 10;
$number2 = 9;
 
if($number1>$number2) {
echo 'Yes.';
}else {
echo 'No.';
}
?>

Output Screenshot14

Comparison Operators In php
Screenshot14
In this example we are using greater than(>) and smaller than(<)comparison operators. Now in this example, condition is if number1 is greater then number 2 then echo out yes or else no, but condition is true so it will echo out yes.
Now Try Some Examples with yourself giving you code copy and paste see results :-

Code for Example 1 (Screenshot15):-

comparison operators in php
Screenshot15

<?php



$number1 = 10;

$number2 = 9;



if($number1<$number2) {

echo 'Yes.';

}else {

echo 'No.';

}

?>

Code for Example 2 (Screenshot16):-

comparison operators
Screenshot16

<?php



$number1 = 10;

$number2 = 9;



if($number1>=$number2) {

echo 'Yes.';

}else {

echo 'No.';

}

?>


Code for Example 3 (Screenshot17):-

php code
Screenshot17

Code for Example 4 (Screenshot18):-

code php tutorials
Screenshot18

Code for Example 5 (Screenshot19):-

php operators
Screenshot19
Now comparison operators are very important when you work dynamically on website. For example, you want to submit form to check whether password is correct or not

Code for comparison operators (Screenshot20) :-

check password
Screenshot20

Output (Screenshot21):-

php tutorials
Screenshot21
In this example we are matching password is correct or incorrect so, you can see its pretty easy and very useful to check conditions are whether True or False.In this, it will evaluate true as it matches variable values.

Code for comparison operators (Screenshot22) :-

password php
Screenshot22

output (Screenshot23):-

password incorrect
Screenshot23
It will mismatch condition and evaluate false and will echo out incorrect .
Read More

Thursday, 13 February 2014

Variables in php

php variables
Variables
This tutorial is for variables. If you have worked with any other programming language you know what are variables for and what they will do.Values are assigned to variables and variables are of different types.Now in this tutorials i am going to show you how to declare variables by assigning values to standard structure and then variables are echoed out on the browser.So, Usually in programming languages such as JavaScript or for any other language like it we have to use keywords,for example in java we use “var” like var example.





<?php

var name = 'value';

?>



In php we don’t need any keywords to define anything only we need to assign it with “$” dollar sign notation and afterwards we can assign “_” sign or characters or strings or numeric characters also. Assigning can be done in upper-case and lower-case both.
Code for Variables(Screenshot1) :-

Variables
Code For Variables Screenshot1


<?php

echo $text = 'Hello World.';

echo $number = 100;

?>



output (Screenshot2) :-

Code for Variables
Screenshot2


In Screenshot1 you can see codes for string.I have used sign ” notation for numeric value and i am not using any notation but only semi colon “;” . Semi colon “;” is a separator. Echo statementecho’s out the variables.We can assign any value to variables such as floating values, Boolean values,etc., but this we will see later on in if statements.

Code for variables different way (Screenshot3) :-

Variables in php
Code for Different types for variables Screenshot3


<?php

$text = 'Hello World.';

$number = 100;

 echo $text;

?>


Output (Screenshot4) :-

code for variables in php
Variables Screenshot4

It will only echo variable $text contain because we only echoing $text variable Code for variables different way second example (Screenshot5):-

Screenshot5


<?php

$text = 'Hello world.";

$number = 100;

echo $number;

?>

Output(Screenshot6) :-

Variables string
Screenshot6


It will echo out the content of variable $number because we are echoing variable $number. Programming languages are used todeclare different data’s, for example you want to take users age or take users name or anything you need to declare,so either you will store it as string data or you will store it as numerical data like integers (similarly for floats),which is somewhat tedious ! But, I would like to tell you an important aspect of php , that you don’t need to think about what data you are storing, you just simply need to assign “$” Sign in the prefix of variable name following with equal to and the variable value. Declaration of variables in php is quite easy.

Read More

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates