RecordSet::subscripting - jcobban/Genealogy GitHub Wiki
$recordSet[$index]
Up: class RecordSet
For the most part an instance of RecordSet
can be treated like an array. In particular you can retrieve a class instance using a subscript, which is in most cases the primary key of the class. You can create a new instance of a class and store it into the RecordSet
using a subscript. You can delete an entry from the RecordSet
using unset($recordSet[$index])
, although that just removes it from the RecordSet
, not from the database. And, as noted previously you can ask how many entries there are in the RecordSet
using the count function.
Examples:
$countries = new RecordSet('Countries');
$canada = $countries['CA'];
$BIOT = $countries['IO'];
unset($countries['IO']); // remove from RecordSet
$BIOT->delete(); // actually delete the record
$BIOT = new Country(array('code' => 'IO',
'name' => 'Diego Garcia');
$BIOT->save(); // actually add record to database
$countries['IO'] = $BIOT; // add to RecordSet
Note that the RecordSet
is out of alphabetical order by name after these changes.