PHP 5 Power Programming

   »    Book by Andi Gutmans, Stig Sæther Bakken, and Derick Rethans

Computer Education, Training & Tutorial Resources - ComputerEducationWorld.com
Home » Free Computer Books » PHP » PHP 5 Power Programming »

2.8.1 User-Defined Functions
The general way of defining a function is
function function_name (arg1, arg2, arg3, …)
{
statement list
}
To return a value from a function, you need to make a call to return expr
inside your function. This stops execution of the function and returns expr as
the function’s value.
The following example function accepts one argument, $x, and returns its
square:
function square ($x)
{
return $x*$x;
}
After defining this function, it can be used as an expression wherever you
desire.
For example:
print ‘The square of 5 is ‘ . square(5);

(more…)


• • •
 

Operator
Name

Value
==
Equal to
Checks for equality
between two arguments
performing type conver-
sion when necessary:
1 == “1″ results in true
1 == 1 results in true
!=
Not equal to
Inverse of ==.
>
Greater than
Checks if first operand is
greater than second
<
Smaller than
Checks if first operand is
smaller than second
>=
Greater than or equal to
Checks if first operand is
greater or equal to second
<=
Smaller than or equal to
Checks if first operand
is smaller or equal to
second
For the following two operators, automatic type conversions are not per-
formed and, therefore, both the types and the values are compared.
Operator
Name
Value
===
Identical to
Same as == but the types
of the operands have to
match.
No automatic type conver-
sions are performed:
1 === “1″ results in
false.
1 === 1 results in true.
!==
Not identical to
The inverse of ===.

(more…)


• • •
 

2.5 Basic Data Types
21
Examples:
‘Hello, World’
‘Today\’s the day’
2.5.3.3 Here-Docs
Here-docs enable you to embed large pieces of text in
your scripts, which may include lots of double quotes and single quotes, with-
out having to constantly escape them.
The following is an example of a here-doc:
<<<THE_END
PHP stands for “PHP: Hypertext Preprocessor”.
The acronym “PHP” is therefore, usually referred to as a recursive acronym
because the long form contains the acronym itself.
As this text is being written in a here-doc there is no need to escape the
double quotes.
THE_END
The strings starts with <<<, followed by a string that you know doesn’t
appear in your text. It is terminated by writing that string at the beginning of
a line, followed by an optional semicolon (;), and then a required newline (\n).
Escaping and variable substitution in here-docs is identical to double-quoted
strings except that you are not required to escape double quotes.

(more…)


• • •
 

PHP 5 Basic Language
“A language that doesn’t have everything is actually easier to
program in than some that do.”–Dennis M. Ritchie
2.1 INTRODUCTION
PHP borrows a bit of its syntax from other languages such as C, shell, Perl,
and even Java. It is really a hybrid language, taking the best features from
other languages and creating an easy-to-use and powerful scripting language.
When you finish reading this chapter, you will have learned
The basic language structure of PHP
How PHP is embedded in HTML
How to write comments
Managing variables and basic data types
Defining constants for simple values
The most common control structures, most of which are available in
other programming languages
Built-in or user-defined functions
If you are an experienced PHP 4 developer, you might want to skip to the
next chapter, which covers object-oriented support of the language that has
changed significantly in PHP 5. (more…)


• • •
 



captcha PHP Script Free PHP captcha script free php
Website Design by WebWalas.com