Operators in PHP

October 3, 2011 Posted by Admin




Operators in PHP programs, functions to manipulate a value. With the operator, a function can be run and are dynamic. The values ​​in an operation  called operands. In an operation of multiplication 4 * 7, the value of 4 and 7 can be called operands.

String Operators in PHP
String operator is the operator used to combine text, both text with a variable or a text with other text. The operator is declared by providing a dot (.) Among operands in an operation.

<?
$ = “Hi”;
$ b = “Congratulations to learn PHP”;
$ c = $ a. “.”. $ B;Echo “<br> $c”;
/ /$c variable contains the “Hi Congratulations to learn PHP ”
?>

If the program is run in a browser, it will generate the words “Hi Congratulations to learn PHP”, $c variable is a combination of variable $a of value “Hi”, “text” and $b variable of value “Congratulations to learn PHP”.

Arithmetic operators in PHP
This operator for mathematical operations, such as addition, subtraction, multiplication, and division.

$ a% $ b Modulus remainder of $ a divided by $ b

Operator Operation Specification
$a + $b Addition $a plus $b
$a – $b Reduction $a – $b
$a * $b Multiplication $a multiplied $b
$a / $b Division $a divided by $b
$a % $b Modulus remaining results of $a divided by $b

 

Operators Increment / decrement in PHP
Operators Incremen / decrement operator is an addition and subtracting the value of the difference value 1 (one). If the operator is placed before a variable, say $a++ or $a–, then the value of $a will be increased or decreased by the value 1 (one) before the operation is run. If the operation is placed after the variable, say $a++ or $a–, then the value of $ a will be increased or decreased by the value 1 (one) after the operation is run.

Operators Operations Specification
++$a Pre-Increment $a plus one, then the operation is run
$a++ Post-Increment operation is executed, then $a plus One
–$a Pre-decrement $a minus one, then the operation is run
$a– Post-decrement operation is executed, then $a plus One

Here is an example program increments and decrements

// Increment and decrement operators
// Operator.php
$a = 1;
Echo”operation ++\$a value of \$a =”.++$ a;
Echo”operation \++$a value of \$a =”.$a ++;
Echo”operation –\$a value of \$a =”.–$a;
Echo”operation \$a– value of \$a =”.$a–;

Try and see the results.

 

Bitwise operators in PHP
This operator function produces a binary value. Namely 1 or 0;

Operator Name Sample Description
& And $a & $b Bit will be worth 1 if $a and $b to 1
| Or $a | $b Bit will be worth 1 if $a or $b -value 1
^ Xor $a ^ $b Bit will be worth 1 if $a or $b, but not both equal to 1
~ Not ~$a Bit will be worth 1 if $ a is 0
<< Shift Left $a << $b Shifts the bits of $ a as $ b steps to the left. Each step has a meaning “multiplied by two values​​:
>> Shift Right $a >> $b, Shifts the bits of $ a as $ b steps to the right. Each step has a sense of “divided by the value of two”

Logic operators in PHP
Logical operators almost have the same function as the comparison operator, ie as a control structure of the program.

Operator Name Sample Description
And / && And $a and $b / $a && $b Produces true if $a and $b are true
Or /|| Or / || $a or $b / $a || $b Produces the value true if either value of $ a or $ b or both are true
Xor Exclusive or $a xor $b Produces true if any of the $a or $b is true
! not !$a Produces true if $ a is not true

 

Operators Presedence in PHP
Presedence is a sequence of operations in accordance with the level of the operator. Thus, arithmetic operations executed in the order / higher level first. Here is a table the execution priority of operators highest to lowest level:

Priority Number Operator
1 () {}
2 ~! ++ – $ &
3 , * /%
4 + -
5 <>=
6 ==! =
7 &
8 ^
9 !
10 &&
11 ||
12 =+=-+/ =&=|=^=
13 .=
14 And (&&)
15 XOR (||)
16 OR

Consider the following example:

$ result = 10 -5 * 4

The results of this operation will result in the value of -10, not 20 because the operators * (multiplication) have a higher level than the – (subtraction) Therefore, the sequence of operation is 5 * 4, then used to reduce 10.

 

Variable Value operation of an HTML Form

One feature is a dynamic web form that can be utilized to provide visitors to send information to the server. Thus, there are two-way interaction between visitors and webmasters, so that a website becomes more dynamic.

In making this form to note is <form> tag and its attributes, such as method, action, and other data input. Action is an attribute that indicates that the data fields or information will be sent to a file, process the data to be accessed. Attribute selection method has two kinds of values​​, ie POST and GET.

  • If using GET , then all entries are sent to the server in a single URL
  • If using POST, the data field is sent to a separate server with a text URL

Weaknesses GET method is used as a parameter data will appear in the URL. Moreover, the GET method can not send large amounts of data. Further, not less important is the name of input data because this data control’s name will be a variable that carries entries of the form.

Incoming search terms:

  • adressing incremented variable php
  • android math operators tutorial
  • arithmetic operator in android
  • arithmetic oprations programs in android
  • php difference between amd and && operators
  • php text operators

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>