array

Conway's Game Of Life In PHP

12th April 2020 - 7 minutes read time

I was saddened to hear of the passing of the Mathematician John Horton Conway today so I decided to put together a post on his 'game of life' simulator.

This game of life, more commonly called Conway's game of life, was devised by John Conway in 1970 and is a way of modelling very simple cell population dynamics. The game takes place on a two dimensional board containing a grid of orthogonal cells. The game is technically a zero player game in that the initial setup of the game dictates the eventual evolution of the board.

Sieve of Eratosthenes In PHP

5th July 2013 - 3 minutes read time

The sieve of Eratosthenes is named after Eratosthenes of Cyrene who was a Greek mathematician who devised a mechanism to find a sequence of prime numbers using a simple algorithm.

Normally, looping through a list of numbers and finding the primes can be an expensive process. The seive of Eratosthenes is one of the most efficient way of working out all of the smaller prime numbers below (below 10 million or so).

Format A List Of Items In PHP

8th January 2010 - 4 minutes read time

It is usual when writing a list of items to separate each item with a comma, except the last two items, which are separated with the word "and". I recently needed to implement a function that took a string and converted it into a list of this type so I thought I would expand on it and post it here.

PHP Array Of Canadian States

23rd April 2009 - 1 minute read time

Use the following array to print out a list of Canadian states, also know as provinces.

PHP Array Of USA States

23rd April 2009 - 1 minute read time

Use the following array if you want to print out a list of USA states either as a list, or as a select box.

PHP Array Of UK Counties

4th March 2009 - 1 minute read time

Use the following code to create an array of counties in the UK.

Serialize And Unserialize With PHP

30th June 2008 - 2 minutes read time

If you have an object or array that you want to save until a later you can use the serialize() and unserialize() functions. The operation of the functions are straightforward. To serialize() an array just pass the serialise function the array like this.

PHP Function To Work Out Average Values In Array

11th March 2008 - 2 minutes read time

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.

Append One Array To Another In PHP

12th February 2008 - 2 minutes read time

Appending arrays in PHP can be done with the array_merge() function. The array will take any number of arrays as arguments and will return a single array. Here is an example using just two arrays.