Search code examples
phphtmlquadtree

How do I... Quadtrees!


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).


Solution

  • 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.