Location: PHPKode > scripts > ndArray > ndarray/README.TXT
The problem goes as follows -
 1. I had to store class names, it's associated db table, and the filename of the class.
 2. Usually only 1 of these factors was known.
 3. The data was in continuous flux.
 4. It needed to be faster and more flexible than a database.
 5. I could not think of a better way to do it. (there probably is)

How it works -
Build an array of associative array's that looks something like:
$aFoo = array();
$aFoo[0] = array();
$aFoo[0]['fieldName'] = 'foo'; // Insert your field name here. The key 'fieldName' has to be there.
$aFoo[0]['required'] = true; // True or False? Should the field be required when storing data?
$aFoo[1] = array();
$aFoo[1]['fieldName'] = 'bar'; // The name of another field to store data in.
$aFoo[1]['required'] = false; // Is this one required?

Then create the object like:
$oArrayCube = new ndArray($aFoo); // $aFoo is used as a blueprint for the data structures.

How to use it -

Storing data:
$aData = array();
$aData['foo'] = 'someData';
$aData['bar'] = 'moreData';
$key = $oArrayCube->insert($aData); // Returns an integer that is the address to get it back out again. 
$aData = null; // Go ahead and kill the original, its stored.

Getting data:
$aData = $oArrayCube->get($key); // Now all the data is back.
$aKey = array(); // Build an array of keys to get
$aKey[0] = 1;
$aKey[1] = 2;
$aData = $oArrayCube->get($aKey); // Now $aData is an array of associative arrays containing data.

Updating data:
$oArrayCube->insert($aData, $key); // Store the data in $key, do not generate a new $key.

Finding data:
If you don't have a key to get the data, then you have to search for it.
$aKeys = $oArrayCube->search('someData'); // Returns an array of keys that matched.  Look in all fields.
$aKeys = $oArrayCube->search('someData', 'foo') // Returns an array of keys that matched.  Only look in field 'foo'.
After you have the matching keys, then you can $oArrayCube->get() them.

Removing data:
$oArrayCube->delete($key); // Returns True/False.  Pretty self-explanatory

$oArrayCube->reindex(); // For the most part, this should not have to be done.  Keys #'s may change.  Clears out empty keys.

Brian Roach
Comments, critiques, and better ways are always welcome.
Return current item: ndArray