 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
Glossary Navigation |
 |
| A |
Algorithm
An algorithm is a method or process to solve a particular problem
|
Array
An array is a collection of items, encapsulated into a single, neat unit. Arrays are generally used to keep closely related items together; a list of colours, names, etc..
Usage is covered in detail in the PHP manual: http://php.net/types.array
Examples
PHP Code:
$colors = array('red', 'blue', 'green', 'yellow');
echo $colors[2]; // green
$person = array('name' => 'Peter', 'age' => '23', 'location' => 'Scotland');
echo $person['name']; // Peter
|
Assignment
You assign a value to a variable. Assignments are done using a single equals sign. For example - $myVar = 5 - here you are assigning the value of 5 to $myVar
|
| B |
Block
A block, or code block, is the PHP code between 2 curly braces
|
Boolean
A boolean is a data type that can only equal either TRUE or FALSE
|
| C |
Class
A class is an entity that encapsulates properties and methods. A class is made of properties (variables) and methods (functions), and can also contain class constants.
More can be found here: http://uk.php.net/class
|
Class Constant
Class constants are set within a class and can only be accessed by the class they were set in. They are created a little differently from a typical constant, but share the same characteristics: cannot be unset, changed, should be uppercase, underscore instead of a space. Class constants are defined like so:
php Code:
const MY_CONSTANT = 'My Data';
|
Comments
Comments make your PHP script easier to read. You can create single line comments by placing // at the begining of the line, or multiline comments by starting the comment block with /* and ending it with */
|
Comparison
When you compare two values or variables. Straight comparisons are done using two equal signs. For example - if ($myVar == $otherVar) - or - if ($myVar < $otherVar)
|
Condition
A condition is used to control loops and is generally a Boolean value
|
Constant
A constant is a way of storing a text item or number that cannot change. Constants cannot be unset or modified and are used for such things as database credentials. A typical constant may be created like so:
php Code:
define('MY_CONSTANT', 'My Data');
Constants should always be upper cased and contain underscores instead of spaces.
|
| D |
Declaration
A declaration is when you declare your variables and their types at the top of your script / class
|
Do While
The same as while, accept it executes the code once before checking the condition. Good for code you know needs to be used at least once or more.
Examples
[php]
do
{
//do stuff here
}
while($condition == true);
Note
See the while loop for further explanation on the loop.
|
| E |
Entity
An entity (UML Class) is any "thing" about which facts or details can be stored; for example, physical existence, person, object or an event.
|
Expression
An expression is any code that has a value. For example: "$a == $b" or "$a - $b"
|
| F |
For
A type of loop designed for looping through code when you know how many times you want to go though it.
Examples
PHP Code:
for($i=0;$i<8;$i++)
{
echo "I have looped though $i times<br />";
}
|
Foreach
Foreach is a way to loop over elements in an array.
Examples:
Taken from http://us.php.net/foreach
PHP Code:
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
|
Formatting
This generally refers to the layout and readabilty of your PHP code. Good formatting includes correctly indented blocks and proper use of whitespace
|
Function
A function is a reuseable block of code that you can run as required. A function definition would look something like:
PHP Code:
function myFunction()
{
// function content here
}
You would then run your custom function as you would a normal function:
In Object-Orientated Programming, functions are also known as Methods.
|
| L |
Loop
A loop will repeat a block of code until you tell it to stop. Types of loops include: For, While, Foreach, Do
|
Loops
See For, while, Do While and Foreach.
|
| N |
Namespace
In the PHP world, namespaces are deigned to solve two problems that authors of libraries, and applications encounter when creating re-usable code elements such as classes or functions:
1. Name collisions between the code you create.
2. Ability to alias Extra_Long_Names designed to alleviate the first problem, improving readability of source code.
PHP Namespaces provide a way in which to group related classes, functions and constants. Here is an example of namespace syntax in PHP:
PHP Code:
# Create our namespace.
namespace Main;
class App {
public function test() {
return __METHOD__;
}
}
# Alias our namespace, and class to "MA" for readability
use MainApp as MA;
# Create new instance of our object "App"
$obj = new MA();
# The following line will output Main\App::test
echo $obj->test();
|
Nesting
Nesting is to put code inside of other code. Most commonly used in loops and if statements - for example, you could next an if() statement inside of another if() statement.
|
| O |
Object
Objects are class instances, they are initialized by the class constructor of an object using the keyword "new":
$object = new stdClass();
|
Operators
In PHP, examples of operators would be +, -, *, /, =, ==, and so on. Operators are generally used in comparisons and arithmetic
|
| S |
Syntax
Syntax in PHP refers to the "grammer" used. And example of PHP syntax could be that each line must end in a semi-colon
|
| T |
Ternary Operator
This is a very useful technique for assigning a value to a variable while evaluating a statement in the declaration. Remeber that the result of the statement will be the value assigned to the variable.
PHP Code:
$a = false;
$foo = $a == false? "Berry" : "Fruit";
print ($foo);
// will output: "Berry"
// this is the same thing as doing:
$a = false;
$foo = null; //you would have to declare the variable here first if register_globals is off
if ($a == false) {
$foo = "Berry";
} else {
$foo = "Fruit";
}
print ($foo);
// again, outputs: "Berry"
Click Here For More Information
|
Types
Types of variables - for example, int, string, float, etc
|
| V |
Variable
A variable is simply a place to store data. For example, if you wanted to store a phone number you could do so using a variable. In PHP all variables begin with a dollar sign ($) Variables can hold different types of data, for example, numbers, objects and strings. However, as PHP is a loosely typed language, variables data types do not need to be explicitly declared.
|
| W |
While
A loop designed for looping though code while a condition is true instead of a known amount of times. Be careful with this loop, it is easy to make it endless.
Examples:
PHP Code:
while($condition == true)
{
//do stuff here
}
Note
The condition does not have to be literally true, it will loop on whatever the condition is in the parameters.
|
|