Function Samples
Sample :
Sample use of a function in a PHP script.
Filed under: Basic Programming, Sample Code by Avatar
No Comments »
Where You Learn PHP the easy way
Sample :
Sample use of a function in a PHP script.
Filed under: Basic Programming, Sample Code by Avatar
No Comments »
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 [...]
Filed under: Basic Programming by Avatar
No Comments »
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 [...]
Filed under: Basic Programming, Sample Code by Celine
No Comments »
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 [...]
Filed under: Sample Code by Celine
No Comments »
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 [...]
Filed under: Basic Programming, Sample Code by Avatar
No Comments »
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, [...]
Filed under: Basic Programming, Sample Code by Avatar
No Comments »
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 [...]
Filed under: Basic Programming, Sample Code by Avatar
No Comments »
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 [...]
Filed under: Sample Code by Avatar
No Comments »
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: [...]
Filed under: Basic Programming, Sample Code by Avatar
No Comments »