Posted in Basic Programming, Sample Code | August 10th, 2010 | No Comments »
The array_count_values() function returns an array which contains the keys of the original array’s value and the value is the number of occurences. A sample of it’s use is shown below:
$a=array("Mouse","Cat","Dog","Cat");
print_r(array_count_values($a));
?>
Which would give us an output of : Array ( [Mouse]=> 1 [Cat]=> 2 [Dog]=> 1 )
The next functions are used to compare the contents of one array against one or more arrays either returning the key, keys and contents or solely the contents of the specified fields that result from their comparisons. They are array_diff(), array_diff_assoc(), array_diff_key(), array_diff_uassoc() and array_diff_ukey(). all of these are used to determine the difference between a set of arrays returning either the keys or contents to give the results of the said array comparison/s.
Posted in Basic Programming, Sample Code | July 10th, 2010 | No Comments »
The array_chunk() function on the on the other hand as the name implies, divides an array into chunks or several tables from the source table. The syntax goes something like array_chunk(array,size,preserve_key), wherein the array is the table that would be divided, the size is the number of elements which the new arrays are to contain and the preserve key which can either be true or false is used to either retain or revise the key or pointer value of the original table. An example is shown below:
$a=array(�a�=>�Cat�, �b�=>�Dog�, �c�=>�Horse�,�d�=>�Cow�);
print_r(array_chunk($a,2);
?>
The code would have an output of:
Array (
[0] => Array ( [0] = > Cat [1] => Dog )
[1] => Array ( [0] => Horse [1] => Cow )
)
As we can see, the original array has been divided into two arrays array0 and array1 and a value that is not given for the key had it assigned a new key for each of the tables. Another example would be :
$a=array(�a�=>�Cat�, �b�=>�Dog�, �c�=>�Horse�,�d�=>�Cow�);
print_r(array_chunk($a,2,true);
?>
This would then give us ;
Array (
[0] => Array ( [a] = > Cat [b] => Dog )
[1] => Array ( [c] => Horse [d] => Cow )
)
This shows the significance of the retain key field wherein the two new arrays retained their original keys. The reverse of which would be the array_combine() which divided the array into one which holds the keys and one with the values.
Posted in Basic Programming | June 10th, 2010 | No Comments »
As with all programming languages PHP has different variable types such as numeric, character, string and Boolean types. Boolean variables in PHP always return either true or false, integers are whole numbers, floating points are decimal or scientifically notated and strings are a chain of characters. Sounds familiar, well they are and they are mostly standard across the various programming languages. For a more in-depth discussion on the different data types of PHP go visit the manual page.
We next discuss operators such as the assignment operator which allows you to assign values to variables allowing complex operations to be constructed into more and more functional programs.
Posted in Basic Programming | May 10th, 2010 | No Comments »

More than a quarter of all software vulnerabilities identified among the Common Vulnerabilities and Exposures (CVE) listed and recorded in the National Vulnerability Database is related to PHP. This makes PHP susceptible to hackers who develop scantily built applications written in PHP. Most of these vulnerabilities can be slightly exploited without being logged on the computer hosting the exposed application. Because of bad programming habits such as failing to check data before entering into a database, and certain features, such exploitation is possible.. This kind of attacks is not limited to PHP and can mostly be avoided by following the appropriate coding procedures and principles.
Posted in Basic Programming | April 10th, 2010 | No Comments »
The major notable difference with PHP against other languages with regards to variables is that PHP is more “intelligent”. In C for example, variables have to be explicitly defined as either numeric or alpha-numeric and can only be used to store that defined specific form of data. PHP like all other languages supports a lot of variable types such as integers, floating point numbers, arrays and strings but with one major difference, variables are recognized automatically based on their use and the context of their use. This makes your (programmer’s) life a whole lot easier. PHP variables are defined with a “$” symbol preceding the variable name. It should also begin with either an underscore or an alpha character.
Posted in Basic Programming, Sample Code | March 10th, 2010 | No Comments »
Now, to make you a better programmer we all know the value of comments. This allows you to understand the code that you have written defining and given meaning to operations as you build them up. You start with the terminators used by PHP and end with them as well. Single line comments look like this �// comment� and Multi-line ones use the syntax /* comment comment*/. A better example would be the one below:
//comment
/* comment
Comment*/
?>
In the next post we take on the best parts of PHP which would be variables which is essential in all programming languages.
Posted in Basic Programming, Sample Code | February 10th, 2010 | No Comments »
As you might have seen, all of the PHP statement ends with �;� which would be somewhat similar to Perl. The valid HTML code that was handed back to the server was :
Who are You?
My name is MacGyver.
More in the coming posts when we dig deeper as we widen our understanding of PHP.
Posted in Basic Programming | January 10th, 2010 | No Comments »
The first post had you making a program that was equivalent to the “Hello World” program used for teaching basics of a programming language and here’s how it worked. When the script was requested by opening the web page, Apache intercepted the request and passed it onto PHP which parsed the script looking for the code in between the terminators and then doing the requested operation which was to display the text contained within the echo command. This result was given back to the server then again to the client. The output contained a valid HTML so the browser was able to understand it and execute the requested operation.
Posted in Basic Programming, Sample Code | December 10th, 2009 | No Comments »
This function combines two arrays where the first array is treated as the key and the second array as the contents of the said table. The syntax goes like this : array_combine(array1,array2), wherein the array1 is the table which contains the keys values, and the array2 is the contents. It should be noted that these two tables or array�s should have equal amounts of contents for it would become problematic if there was an error in the combination process. An example of the process is shown below:
$a1=array('a','b','c','d')
$a2=array2("Mouse","Rat","Rodent","Mice")
print_r(array_combine($a1,$a2))
?>
The output of which would give us a single table :
Array ( [a] => Mouse [b] => Rat [c] => Rodent [d] => Mice )
The function combined the two tables giving a single table that combines the keys and the contents. More in-depth discussion on the different array functions which in future posts would be the backbone of applications we will be building.
Posted in Basic Programming | November 15th, 2009 | No Comments »

Once you open your PHP application such as Dreamweaver, chances are you will be overwhelmed on what you can do with it. In the early stages, you will find yourself being taken aback for the reason that you will see a lot of features such as command lines and scripts that you can use.
Dreamweaver does allow you advanced programming with PHP. However, do remember that you have to start from the bottom. Learning the basics first and slowly integrating them as you go along the way will be the best way to approach it. In short, don’t let your enthusiasm for the software get the best of you. Take it one step at a time.