public function select_by_field($tbl, $field, $where = '', $f_szClass = 'SimpleArrayObject') { $szClass = class_exists($f_szClass, true) ? $f_szClass : 'SimpleArrayObject'; $r = $this->query('SELECT * FROM ' . $tbl . ($where ? ' WHERE ' . $where : '') . ';'); if (!is_resource($r)) { return false; } $a = new SimpleArrayObject(); while ($l = mysql_fetch_assoc($r)) { $a->set($l[$field], new $szClass($l)); } return $a; }
/** * @todo test for fully recursive arrays within arrays when the serializer supports */ public function testArrayRecursion() { $simpleArray = array(array("value1", "value2", "value3"), array("value1", "value2", "value3"), array("value1", "value2", "value3")); $object = new \SimpleArrayObject(); $object->setArray($simpleArray); $arrayObject = $this->doSerialize($object); $this->assertArray($simpleArray, $arrayObject->getArray()); $arrays = $arrayObject->getArray(); for ($i = 0; $i < count($simpleArray); $i++) { $this->assertArray($simpleArray[$i], $arrays[$i]); } }