Databases Reference
In-Depth Information
$x[0] = 10;
$x[1] = 20;
$x[2] = 30;
The style you use is a personal preference; the former style is compact and simple, while
the second style is familiar to most programmers.
Manipulating Variables
You can manipulate variables to modify the values they contain. For example, you can
add the values in two variables and place this value in a third variable:
$x = 4;
$y = 7;
$z = $x + $y;
You could in fact place the sum into an existing variable, such as $x :
$x = $x + $y;
Of course, this would overwrite the previous value (4) with the sum (11).
The arithmetic shortcuts that work in many other languages also work in PHP:
$x = 4;
// add one to $x in three different ways
$x = $x + 1;
$x++;
$x += 1;
// subtract one from $x in three different ways
$x = $x - 1;
$x--;
$x -= 1;
// Multiply $x by two in two ways
$x = $x * 2;
$x *= 2;
// Divide $x by three in two ways
$x = $x / 3;
$x /= 3;
To concatenate strings, use the . operator:
$x = "Hello";
$y = "world";
// $z contains "Hello world";
$z = $x . " " . $y;
 
Search WWH ::




Custom Search