tags:

views:

109

answers:

3

How can I go about creating a quadtree in PHP, is it even possible?

I would like a "grid like" layout.

So each "node" has 4 "exits" - north, south, east and west.


Does anyone have some sample PHP code of a Quadtree because I couldn't find any documentation specifically for PHP :(

I'll be your best friend... (possibly some Rep in there too).

+3  A: 

The same way you do in any other language. PHP has references, variables, and even some OO capabilities. There is nothing missing to make a quadtree implementation even difficult, much less impossible.

Donnie
A: 

You could start by looking at doubly linked lists, which would give you either a row or a column in your grid (but not both), then look at extending that to reflect the second dimension.

Mark Baker
+2  A: 

If I'm understanding your question correctly, then the following might be what you are looking for:

$map = array(
    array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4)),
    array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4)),
    array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4)),
    array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4))
);

$map[0][3][3] = "END OF ARRAY 1";
$map[1][3][3] = "END OF ARRAY 2";

etc.

Ardman
I don't think this should be the accepted solution - it's just a 3D array.. not really what OP is meaning to ask
Jeriko
This would indeed deserve a class, which could implement ArrayAccess Traversable, Countable interfaces
greg0ire