Contact Us

Donate your PHP arrays!

Posted on 29/1/09 by Felix Geisendörfer

Today I needed a list of mime types and extensions to determine the proper extension to assign to a file with a certain mime type. It wasn't difficult to find one.

However, as always when looking for tables and stuff like this on the web, I had to convert the data for using it in PHP. Usually I'd use my text editor and a few regex for the job.

But not today. Today was the last time I wasted energy on importing trivial data sets into PHP.

Why? Well, because I believe there is a fortune lost in man hours in the process on a daily basis. It is time for stopping that.

It is time for a new project called php arrays. (Warning: don't open anything but extensions.php / mime_types.php in your browser, it may freeze due to client-js syntax highlighting. Click the download link of the whole repo instead.).

Basically it is just a collection of PHP arrays, each containing one big array. So far I have done a little work in making two generators that currently produce the following arrays: big_cities.php (population > 15000), countries.php, extensions.php, mime_types.php and time_zones.php. Whenever I need to work with other stuff I'll add it there as well.

Now it is time for you to join the fun and share PHP arrays you generated or aggregated in the past. Fork the project on GitHub or send me a link to your array paste.

-- Felix Geisendörfer aka the_undefined

PS: What other arrays would like to see added to the collection in future?


You can skip to the end and add a comment.

Mike said on Jan 29, 2009:

Why not just submit the lists to listable ( and work off there instead?

Petr 'PePa' Pavel said on Jan 29, 2009:

It would be great if the data was live - processed from Wikipedia on the fly. Something along these lines:

Jonah Turnquist said on Jan 29, 2009:

Nice idea. You could even develop a dedicated website for the same idea even, and make it more automated. I'm sure there are hundreds of lists people could use for different things.

For large lists though, isn't it better to use a database table instead? Loading an array with almost a half a million elements does not seem like a good idea.

Perhaps the project could hold SQL code of table insertions also?

dave  said on Jan 30, 2009:

mike has a good suggestion. plus, it's nice to see andre's site get some attention.

sourav said on Jan 30, 2009:

hi Felix,
I have submitted a php class on class is also available (under GNU GPL-2 license) with example on This call serializes an array (of any dimension) and set is as a Constant and it can also unserializes the array from the Constant or can return the value of a particular element if it is requested with the element key or index

ben hirsch  said on Jan 30, 2009:

great idea!

I'd like to also see the data live somewhere and a way to access it via an api.

Silver Knight  said on Jan 31, 2009:

Fantastic! Thank you for this, Felix! Just today I was looking at and planning to write code to parse that country list into a usable PHP array, but it is by FAR easier for me to just download your country array and use that instead. I will happily contribute any useful arrays I end up using, as this idea of yours is just entirely TOO useful to ignore. Thank you again. :)

Silver Knight  said on Jan 31, 2009:

Sorry to post again so soon, but I forgot to mention this in the previous comment... I've been thinking to ask for this feature for a while now, but I keep forgetting to say anything about it. Would it be possible for you to add a "Preview Comment" option in addition to the "Add Comment" so that we can have a quick look at how our comment will look once posted BEFORE it actually gets posted? Perhaps an option for us to somehow go back and edit a previously posted comment might also be nice if in any way possible. Anyhow, as always, thank you for your useful and informative / educational blog. Keep up the great work. :)

Tim Koschützki said on Feb 01, 2009:

Jo Silver Knight, sure that feature is noted down. Let's hope we'll find time soon to implement it. Good idea!

Silver Knight  said on Feb 01, 2009:

Greetings, Mr. Tim... Is your site written in CakePHP, and is the code posted in a GIT repository anywhere? If so, I'm sure I could find time sometime to implement a small feature like a "Preview Comment" button for y'all. ;)

Tim Koschützki said on Feb 01, 2009:

Urm yeah the site is fully written in Cake, but it's not in a public repository yet. Felix and I have been back and forth on releasing the code, but there will be sometime.

Others contributing features is actually pretty welcome.

Silver Knight  said on Feb 02, 2009:

Right on. No worries, sir. Let me know when you guys do go public with your site code, and I'll do the same when I go public with mine (which has not yet gone "live" but is nearly ready to). ;)

Jon said on Feb 04, 2009:

now, i'm definitely not trying to start some competition

I've been throwing this idea around, some may have heard me blabbing in irc and whatnot already, but I want to write something in cake for my apps to be pulling data sets like this, generic shtuff mostly like states, currencies, zip codes, etc., on the fly.

basically i want to have a centralized source to host them, and perhaps a datasource written for cake i can recycle for any apps looking to use them. maybe this isn't the best solution, but it just seems so inefficient to have some of these generic datasets which rarely change (though they can) in so many different places.

listable is cool, haven't seen that before. there's also a rad site I found called freebase ( which seems to be pretty nice.

also, this is a great article along these lines:

what do you think?

p.s. your comments notification is rendering as a text input rather than a checkbox

Felix Geisendörfer said on Feb 04, 2009:

Jon: Please! Go ahead and start something like this. I vote for a web interface where I can export to PHP - that's all I need.

About the checkbox: You caught me in the middle of rolling out the feature, CakePHP's cache wasn't purged yet so the new field was unknown to the form helper : p.

Sonic  said on Feb 11, 2009:

Hey guys,

I love the ideas mentioned here, everything. Should we pull our resources together and start something?

@Felix: One note. I noticed in the array for Ireland you only have UK in the neighbours key. It should also include the Isle of Man. In the Isle of Man array you have no neighbours. This should include Ireland and the UK. Other than that I love it. Well done!

Jon said on Feb 11, 2009:

this is for, as phishy would say, funsies.

i have to develop something regardless, but if anyone would care to join, or just share what they come up with, i would be stoked!

Frank said on Feb 11, 2009:

This is great, thanks very much for providing it. The countries array I'm looking at seems remarkably comprehensive.

Tim said on May 19, 2009:

hey, Thanks for this

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.