Hi there!
I'm trying to link an array key to an object property, here's some sample code:
class Table {
private $_columns = array();
public function addColumn($c) {
$this->_column[] = $c;
}
public function getColumn($index) {
// ???
}
}
class Column {
public $Index;
.
.
.
}
What I am trying to achieve is to have a column index that is a Column object property. So when I say $mycolumn->Index=4; I mean be the 4th column inside the table. And when I say $mytable->getColumn(4); I mean give me the 4th column of $mytable.
I don't care the what are the column keys at table initialization(the $_columns keys), I'd like to explicitly define the column indexes for sort, save/load, ... and other purposes.
I believe there is no such thing as referenced array keys, where the array key would reference an index variable:
$key = 1;
$myarray[&key]="ABC";
$key = 4;
echo $myarray[4]; //returns ABC
Of course I could always iterate through $_columns array but I think this is not the right solution, too slow.
How would you solve this issue?
Thanks!