Mga Pahina

Linggo, Enero 23, 2011

Php - Assigning Operators

We assign operator in php.  An operator is something that can be used to do operations on values to get a new value. We will look at: Arithmetic, Assignment, Logical, Comparison and Concatenation (string) Operators.

Assignment Operators

Assignment operators are used to set a variable equal to a value or set a variable by doing an arithmetic operation on itself and another value.
Assignment operators are used to set a variable equal to a value or set a variable to another variable's value. Such an assignment of value is done with the "=", or equal character. Example:
  • $my_var = 4;
  • $another_var = $my_var;

Arithmetic Operators:

<?php
$addition = 2 + 4;
$subtraction = 6 - 2;
$multiplication = 5 * 3;
$division = 15 / 3;
$modulus = 5 % 2;
echo "Perform addition: 2 + 4 = ".$addition."<br />";
echo "Perform subtraction: 6 - 2 = ".$subtraction."<br />";
echo "Perform multiplication: 5 * 3 = ".$multiplication."<br />";
echo "Perform division: 15 / 3 = ".$division."<br />";
echo "Perform modulus: 5 % 2 = " . $modulus
. ". Modulus is the remainder after the division operation has been performed.
In this case it was 5 / 2, which has a remainder of 1.";
?>
Output:
Perform addition: 2 + 4 = 6
Perform subtraction: 6 - 2 = 4
Perform multiplication: 5 * 3 = 15
Perform division: 15 / 3 = 5
Perform modulus: 5 % 2 = 1. Modulus is the remainder after the division operation has been performed. In this case it was 5 / 2, which has a remainder of 1.

Logical Operators

<?php
if(statement && statement2){ condition }
if(statement || statement2){ condition }
if(statement != statement2){ condition }
?>

Comparison Operators

<?php
$a_string = "Hello";
$another_string = " Billy";
$new_string = $a_string . $another_string;
echo $new_string . "!";
?>
Output:
Hello Billy!

Sample code:
As i said, they used in programming in php it integrated by c++ and c language that only require this in php languages.
reference: Tizag.com and codingunit.com

Walang komento:

Mag-post ng isang Komento