Function Samples

Sample :

Sample use of a function in a PHP script.

PHP Functions

Now that we know the basic loop statements that are commonly used in PHP, we come to one of PHP’s real power in the form of it’s built in functions. PHP has over 700 built-in functions which gives the programmer a lot of quick and fun ways to do things they would otherwise have to [...]

Loop Statement - foreach

The foreach loop is mostly used to parse through an array that for every loop, the value of the current array content/value is assigned to the $value (after which the array pointer increments by a factor of one) then the next loop results in the next array content/value.
Syntax:
foreach (array as value)
{
code to be executed;
}
Sample [...]

Error messages in PHP 5 has been upgraded! SWEET!

Sometimes, the things matters. If you write this test program in PHP 4 (tested on 4.4.7):
< ?php
function test($arg) { echo "talk like a parrot."; }
test();
?>
An error message pops up like the one below:
Warning: Missing argument 1 for test() in /usr/bin/- on line 2
The error warning illustrates the position of the purpose of the function, but [...]

Loop Statement - For

The for statement on the other hand is used for loops that have a defined number of repetitions. The “for” statement requires three parameters; the initialization of a variable that would be incremented, the condition that is to be satisfied and the number of times the block of code is to be executed. If more [...]

Loop Statements - Do While

The loop statement is used to execute a block of code at least once then repeats the process as long as a set condition is true. As long as the condition results true the loop continues, exiting at false.
Syntax:
do
{
block of code to execute;
}
while (condition);
Sample Code:
The following code will increment the value of at least once, [...]

PHP Loop Statements

A loop in PHP(as well in other languages) performs a block/chunk of code a specified number of times that can be used to save time when you want a piece of code to be executed at different times but with the same function. Loop statements are:
while - performs the block/chunk of code as long as [...]

PHP array_flip() & intersect () functions

The function reverses the contents of an array with the keys as values and the values as keys with the following syntax:
array_flip(array)
Legend:
array - array(name of the array) to be flipped
Sample Code:

Output :
Array([Lizard] => 0 [Mouse] => 1 [Fish] => 2 )
PHP array_intersect() function
Compares two or more arrays, returning an array with the keys and [...]

Php array_fill() & array_filter() Function

the funcxtion simply fills up an array with the contents you specify with the following syntax:
aray_fill(start,number,value)
Legend:
start - a numeric value which denotes the starting index of the key (required)
number - also a numeric value which denotes the number of entries (required)
value - denotes the value which is to be inserted into the array (required)
Sample code:

Output: [...]