You are here: Daniel Dumas »

January, 2009

PHP Operators: Using String Concatenation Operator

You can concatenate or add strings together using the PHP string concatenation operator represented by the period sign ( . ). refer to the examples below.

<?php
// intialize variables
$username = "daniel";
$domain = "danieldumas.com";

// the variable string $username and $domain can be combine using the concatenation operator
$email_address = $username . '@'. $domain;

//the variable $email_address now contains the value "daniel@danieldumas.com"

?>

You can also concatenate simultaneously. . Keep Reading…

PHP Operators : Using Arithmetic Operators

Using Arithmetic Operators in PHP you can perform mathematical operations on PHP variables. refer to the example below.

Using PHP Arithmetic Operator

//define variables
<?php

$num1 = 50;
$num2 = 30;

//Addition
$sum = $num1 + $num2;

//Subtraction
$difference = $num1 - $num2;

//Multiplication
$product = $num1*$num2;

//Division
$quotient = $num1 / $num2;

//Modulus
$remainder = $num1 % $num2;

?>

you may also use the shorthand using the PHP Assignment Operator and Arithmetic Operator together. Keep Reading…