$object = array();
while($row = mysql_fetch_object($result))
{
$object[] = $row;
}
$object = new stdClass($object);
或
class myClass{
private $counter = 0;
public function add($row){
$count = $counter++;
$this->$count = $row;
}
}
$object = new myClass();
while($row = mysql_fetch_object($result))
{
$object->add($row);
}
或
class myClass implements ArrayAccess{
private $counter = 0;
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$count = $counter++;
$this->$count = $value;
} else {
$this->$offset = $value;
}
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetUnset($offset) {
unset($this->$offset);
}
public function offsetGet($offset) {
return isset($this->$offset) ? $this->$offset : null;
}
}
$object = new myClass();
while($row = mysql_fetch_object($result))
{
$object[] = $row;
}
這並不真正使一個很大的意義。你想讓結果對象看起來像什麼? – deceze 2011-12-19 07:36:15
你能否澄清預期結果需要做些什麼?你想要迭代對象嗎? – SeanNieuwoudt 2011-12-19 07:41:59
你想訪問這樣的行嗎? $ object-> 0-> COLUMN 這是不可能的。實際上它沒有任何意義。 – 2011-12-19 07:57:14