views:

135

answers:

2

I'm in the process of creating a PHP data structure based on some data I'm fetching from somewhere.

If I would encode this information in some standard container, like XML or JSON, I would use this structure:

[ {'name': 'Lupin', 'age': '13'}, {'name': 'Igor', 'age': '24'}, ... ];

However I'm a bit unsure what to use in PHP ( Array of Arrays vs Array of Objects ).

One thing is that I don't really care much about readability, but I would like to be able to sort this Array (which can be quite big). For example I might want to sort it for the biggest age, or something else.

So what structure should I use for my data in PHP? I would like some performance comparisons mostly.

+1  A: 

Although the array is the most straightforward approach, do not forget the SPL Datastructures. Depending on the UseCase, they can perform better than an array.

Also, I would suggest not to think too much about performance until it starts to impact the application in a negative way (you know the premature optimization is the root of all evil thing). Your architecture should first and foremost be maintainable. If you have decided to follow the OOP paradigm, then performance cannot be your most important factor. It wasn't designed with speed in mind. When you are using objects, you are trying to tackle complexity, not boost performance.

I'd say use what works for you now. Then do a few benchmarks and when it performs too slow, optimize.

Gordon
+2  A: 

@Temporary Table: MySQL indeed allows creating temporary tables through CREATE TEMPORARY TABLE. These tables are only visible to the current connection, so be sure not to use persistent connections ;)

nikic
I ended up using a database, thanks.
Luca Matteis