Learning PHP - Basic 2

7/17/10

Now part 2 of Learning PHP is about Operator in PHP and Parsing Variable. We will discuss more the theory in this post and the excercise in another post.

Operator
Operator is object between two variable in PHP or it can be in one variable, that will change another variable's value, or the variable's value itself. Hmm maybe you still hard to understand this, look at this example :
$x = 1 + 2;
x is variable
1 and 2 is value
and + is the operator



in another example,
$x = $i++
the ++ is operator too.

There are some operator in PHP :
Logic Operator
Logic Operator will compare two variable with Boolean type and giving the result in boolean too. Look at this table below.
Logic Operator
Logic Operator

For example :
$number1 = 10;
$number2 = 10;
if ($number1 == $number2){
echo "True";
}

In example above, the result of that condition is true, so it will displaying True on browser. If you don't understand about code above, you can read about PHP basic 1.

Assignment Operator 
This operator handle about adding and intialization value into the variable. Look at this table below :

Assignment Operator
Assignment Operator


Arithmetic Operator
Handling Arithmetic operation. Look this table :

Arithmetic Operator
Arithmetic Operator


Relational Operator
Handling about comparing two variable and  giving result in boolean, nearly same as logic operator, but it uses more operator.

Relational Operator
Relational Operator

Parsing Variable
To handle intialization of variable from URL (GET) or form (POST)

  • URL -> GET/REQUEST
Variable initialization from URL (GET) that derived from variable typing that shows in address bar/hyperlink. Example : http://localhost/kursus/php/parsing.php?name=Joe
In this URL there's a variable name, that contain value Joe. To get the value of this variable. we can use :
$_GET['name'] or $_REQUEST['name']
  • FORM -> POST
Variable initialization that derived from form input that sent by user when click 'Submit' Button. Example :
<form action = "<?=$PHP_SELF;?>" method="POST">
<input type="text" name="name">
<input type="submit" name="process" value="process">
</form>
<?php
if(isset($_POST['process'])&& !empty($_POST["process"]))){
echo $_POST['name'];
}
?>

Well.. maybe you think, wth is thatt?!!! Relax, i just wanna explain some meaning of this code. We will practice the PHP in another lesson ok?
Look at that code, there is a form, it explain action which is php_self, php_self is function to reload at the same page, and have method POST. Then again there is an input text that has name = name. It will be used to generate name in the page.
Now look at PHP code, that will echo/display the value of variable name if the value of variable name is set.

Again don't worry, we will learn about this, we will running the code, and look for the result in another post. So stay tune on my blog!



No comments:

 

Tags