PHP Notes 4

PHP Notes 4 Lakshman Gupta - 08/10/2009
PHP Tutorial

Comparison Operators
Example Name Result
$a == $b Equal TRUE if $a is equal to $b.
$a != $b Not equal TRUE if $a is not equal to $b.
$a <> $b Not equal TRUE if $a is not equal to $b.
$a < $b Less than TRUE if $a is strictly less than $b.
$a <= $b Less than or equal to TRUE if $a is less than or equal to $b.
$a > $b Greater than TRUE if $a is strictly greater than $b.
$a >= $b Greater than or equal to TRUE if $a is greater than or equal to $b.
$a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (PHP 4 only)
$a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only)
Logical Operators
Example Name Result
$a && $b And TRUE if both $a and $b are TRUE.
$a and $b And TRUE if both $a and $b are TRUE.
$a || $b Or TRUE if either $a or $b is TRUE.
$a or $b Or TRUE if either $a or $b is TRUE.
! $a Not TRUE if $a is not TRUE.
$a xor $b Xor TRUE if either $a or $b is TRUE, but not both.
String operators: Concatenation: . Concatenation to the end: .=
$str1 = $lastname . ", " . $firstname;
$str2 .= $str3;
Functions
Function declaration:
function my_func ()
{
print "Hello Lakshman!";
} // end function my_func
Function parameters and returning values:
function count_a ($str)
{
$n = substr_count($str, "a");;
return ($n);
} // end function count_a
Function parameters - passing parameters by reference and by value:
function salary_increase (&$value, $inc_rate)
{
$value *= (1 + $inc_rate);
} // end function salary_increase
Returning arrays:
function get_values ($a, $b)
{
$vals = array();
// ...
// statements to put values into the array $vals
// ...
return ($vals);
} // end function get_values