在下面的代码中,print_r
while 循环中的第一个打印不同的故事内容。我遇到的问题是第二条语句从数组中print_r
一遍又一遍地产生完全相同的故事。$stories
$stories = array();
while($row = mysql_fetch_array($result)){
$story->name = $row['Name'];
...
$story->date = $row['Date'];
print_r($story); //for testing
array_push ( $stories , $story );
}
print_r($stories);
编辑:有人要求提供命令行输出,但这是一个托管帐户。如果上述情况不清楚:
从内部循环:
(
[id] => 9370
[name] => Five Below, Inc.
...
)
stdClass Object
(
[id] => 9362
[name] => Peregrine Pharmaceuticals Inc.
...
)
stdClass Object
(
[id] => 9363
[name] => Mitel Networks Corporation
)
...
stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
...
)
循环后:
Array
(
[0] => stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
...
)
[1] => stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
)
[2] => stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
)