Month: November 2008

Delving deeper into the PHP lake…testing if a variable exists in a list

As a PHP developer of almost four years now, I often still come across little problems in coding that make me do the good ol Google search to find the answer. (someday I will have memorised the entire PHP manual, but today is not that day ;-).

Anyway today I was asked about how to do a IN LIST type comparison in PHP. (similar to the mysql IN statement).

A few google searches later revealed that there exists no such PHP command, however the in_array function can be used to perform the task:

$myArray = array(1, 2, 3, 4, 5);

if (in_array($var, $myArray)){
// do some code.

I guess one could also combine the two as follows:

if (in_array($var, array(1, 2, 3, 4, 5))){
// do some code.

I’ll have to test that one, but you get the idea…

Filed under: DevelopmentTagged with:

Simple PHP increment function

Whenever I have to output a numbered list of data I usually run the following code to achieve the required result.

$counter = 0;
// for loop that does all the required code
// end for

but I have discovered a lovely little function that does all this for me.

function increment(&$counter){
return $counter

now I simply call


and it automatically outputs the next numeric.

Great! Simple and easy to use…..that’s the way to code.

Filed under: DevelopmentTagged with: ,

My first published article.

Something of a first for me. I recently started playing around with the CakePHP framework again. I have had some (little) experience with it in the past and with the launch of two CakePHP books I decided it was high time I learned how to use this awesome framework properly.

A few days later I was trying to find a way to integrate my favourite html editor into the framework itself and after a lot of googling, trial and error and a little luck I managed to find a simple, reusable way to integrate the editor into the framework. As this was very helpful to me I posted an article on the CakePHP bakery, and the chaps over there deemed it worthy enough to be published.

You can read it here . Please feel free to send me your comments.

I’m just kinda chuffed the published it. 😉

Filed under: DevelopmentTagged with: , , ,