I am trying to understand how I can build a sort of knowledge tree/ontology using associative arrays and consts in PHP. The following example shows what I'm trying to do:
class Fruit {
public static $TYPES = array("APPLE" => array("GREEN" => Apple::GREEN), array("RED" => Apple::RED));
}
class Apple {
public static $GREEN = array("GRANNY_SMITH" => array("FLAVOUR" => array(Flavour::SHARP, Flavour::SWEET)),
"GOLDEN_DELICIOUS" => array("FLAVOUR" => array(Flavour::SWEET, Flavour::BLAND)));
public static $RED = array("RED_DELICIOUS" => array("FLAVOUR" => array(Flavour::SOUR, Flavour::SHARP)),
"PAULA_RED" => array("FLAVOUR" => array(Flavour::SWEET, Flavour::SOUR)));
}
class Flavour {
const SHARP = "sharp";
const SWEET = "sweet";
const SOUR = "sour";
const BLAND = "bland";
}
From this I want to be able to retrieve values something like:
$flavours = Fruit::TYPES["APPLE"]["GREEN"]["GOLDEN_DELICIOUS"];
So basically I am getting a list of flavours associated with Golden Delicious apples... Is there a better way to represent a static data tree like this in PHP? In Java I would use Enums...
class Flavour.