为 while 循环结果创建一个变量

Sam*_*tha 1 php mysql arrays echo while-loop

while ($topic = mysql_fetch_assoc ($result)); {
   echo "{$topic["overtag "]} ";
}
Run Code Online (Sandbox Code Playgroud)

我的 while 循环的结果显示为:apples orange 香蕉

我希望能够获取所有这些结果并将它们放入一个变量中并使其看起来像这样:$fruits = apples orange 香蕉

我怎么能做到这一点?

Dav*_*han 5

连接运算符 .=

$fruits = '';
while ($topic = mysql_fetch_assoc ($result)); {
    $fruits .= "{$topic["overtag "]} ";
}
Run Code Online (Sandbox Code Playgroud)