function

function

PHP Function To Work Out Average Values In Array

Tuesday, March 11, 2008 - 18:25

Working out the average of a bunch of values is quite a common task, but rather than looping through the array, adding together values as you go and the using the count() function to find out the average at the end.

Category: 

Biased Random Value From Array With PHP

Monday, March 10, 2008 - 18:17

Sometimes you will want to get a random value form an array in a biased random way, that is, you will want certain values to be returned more than others. Here is a function that will generate a single key from an array, with a greater change of a higher value being retrieved.

Category: 

PHP Password Generator

Saturday, March 8, 2008 - 17:15

Here is a very simple function that will generate a string of random characters, ideal if you want to create a password for a new user.

Category: 

Simple PHP Script To Hide An Email Address In An Image

Tuesday, March 4, 2008 - 14:43

Spam is a problem. You want to allow people who genuinely want to get in touch to see your email address, but doing this invariably leads to you getting thousands of spam emails.

One solution is to hide your email address in an image, but it can be a pain to create an image for every email address you need. A better solution is to use the PHP GD functions to create an image at runtime so that your email address is displayed, but is completely unreadable to spammers.

To to this you will need to create an image tag on your website, here is an example.

Category: 

Passing Values By Reference In PHP

Saturday, February 16, 2008 - 15:33

For most functions it is normal for have the function return the output of a calculation. With PHP it is also possible to pass values to the function by reference. A better way of saying this is rather than pass the value of the variable you pass a pointer to the variable itself. When you do this anything that you do to the variable inside the function is also done outside, so if you interact with the variable again it will contain a different value.

Category: 

Sinlgeton Design Pattern With PHP5

Saturday, February 9, 2008 - 20:35

The singleton design pattern is used to centralise an object in an application that is used to store changing variables that can then be accessed by other parts of the program. It allows only the single instantiation of an object, hence the name.

Category: