Zaxnyd
-
Posts
29 -
Joined
-
Last visited
Never
Posts posted by Zaxnyd
-
-
I'm working with 3 groups of data (currently as multidimensional arrays): doctors, procedures, locations.
Each of these need to have knowledge of the other 2. For example, doctors need to know their locations and procedures, locations need to know their doctors and procedures, and procedures need to know which doctors do them as well as where they're offered.
I've tried creating classes, etc, but it's still not all falling together as I'd like. Does anyone have any suggestions for a better method of organizing this data? Classes perhaps?
Thanks [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /] -
Thanks so much for your quick reply; however, I'm still a bit befuddled. [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /]
In the example you proposed, how would one access the created list? Shouldn't the "c1" class be instantiated into an object that is referenced within the "item" class?
To clarify my goal in case of any confusion, essentially the end result I am aiming for is to end up with a series of items who are all referenced within an array. One could effectively create each object and manually insert them into an array immediately after instantiation, but for simplicity's sake and to avoid the error of ever forgetting to any, I'd like it to be automatically done within the item's constructor.
I just know I'm overcomplicating this...
Thanks again. -
I want a class that, upon instantiation, automatically "pushes" the created object into an array.
I have tried numerous ideas with wrapper classes and constructors, but nothing so far has worked. I have a feeling the answer will be painfully obvious once seen, but any assistance would be greatly
This is an example of what doesn't work (disregard any syntactic errors, I freehanded some for simplicity's sake):
[code]
class list
{
var $contents = array();
function add($item)
{
array_push($contents, $item);
}
}
class item extends list
{
var $name;
function procedure($name = "")
{
$this->name = $name;
parent::add(this);
}
}
[/code]
Thanks in advance for your assistance!
Class that "Pushes" its Instances into an Array
in PHP Coding Help
Posted
[code]
class itemlist
{
var $contents = array();
function add($item){
array_push($this->contents, $item);
}
function newitem($data){
$temp = new item($data);
$this->add($temp);
}
}
class item
{
var $data;
function item($data){
$this->data = $data;
}
}
$foo = new itemlist;
$foo->newitem('bar');
[/code]
var_dump($foo) returns:
[code]
object(itemlist)(1) {
["contents"]=>
array(1) {
[0]=>
object(item)(1) {
["data"]=>
string(3) "bar"
}
}
}
[/code]