Hi guys, can you please suggest me a good class that supports sub-sub-sub categories. I tried a lot of them, none of them seems to fit me! I also tried to modify them for my needs, but the more i try, the worse it gets lol :P

If you know a good class, that Can add/remove/update categories with unlimited level, please suggest!

Thank you!

just brainstorming here, but can't you just create a class and have an "add subclass()" method that does a new subclass() and sets a class variable to point to it? then anytime you want to create a new level just call that class?

The problem is to create kinda chain, so when they get displayed!

-First Cat
---Child 1
---Child 2
-----SubChild 1
---Child 3
-----SubChild 3
-----SubChild 4
---Child 4

I hope you understand

like this dude

litter.php

<?php
require_once ('cat.php');

    $mommacat = new cat('First Cat');
    $mommacat->addChild('Child 1');
    $mommacat->addChild('Child 2');
    $mommacat->children[1]->addChild('SubChild 1');
    $mommacat->addChild('Child 3');
    $mommacat->children[2]->addChild('SubChild 3');
    $mommacat->children[2]->addChild('SubChild 4');
    $mommacat->addChild('Child 4');
print_r($mommacat); echo "\n\n\n";
?>

cat.php

<?php
class cat
{
    public $name;
    public $children = array();

    public function addChild($name)
    {
        $this->children[] = new cat($name);
    }

    function __construct($name)
    {
        $this->name = $name;
    }
}
?>

I mean it's not very pretty, but does what ya wanted i think

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.