これは、毎回同じオブジェクトを配列にプッシュしているためです。
代わりに、反復ごとに新しいオブジェクトをプッシュする必要があります。たとえば、$oがstdClassオブジェクトの場合$o = new stdClass、ループ内で使用します。
while($row=mysql_fetch_assoc($result))
{
$o = new stdClass;
$o->pw=$row['password'];
$o->mail=$row['mail'];
array_push($arr, $o);
}
を使用することもできますがmysql_fetch_object、これはおそらくより適切です。
while($o=mysql_fetch_object($result))
{
array_push($arr, $o);
}
上記のオブジェクトのプロパティは、SQL クエリ列に基づいて名前が付けられるため、同じ効果を得るには、クエリを に変更する必要もありますselect password AS pw, mail from account。
最後に、オブジェクトを毎回クローンするという別のオプションもありますが、ほとんどの場合、他の方法が推奨されます。
while($row=mysql_fetch_assoc($result))
{
$o = clone $o;
$o->pw=$row['password'];
$o->mail=$row['mail'];
array_push($arr, $o);
}