dongluan7821 2014-04-10 21:08
浏览 50
已采纳

如何从foreach循环输出中分配PHP变量?

I have a foreach loop which prints out the usernames of all entries in a database table like so:

foreach($results as $result){

echo $result->username;
echo '<br>';

}

As more and more users are added to the table, the list will grow. I would like to take the complete list and assign each entry to a separate PHP variable for use later on the PHP script. What is the best way to do this?

  • 写回答

6条回答 默认 最新

  • donglu5728 2014-04-10 21:11
    关注

    You don't want individual variables, try an array:

    foreach($results as $result){
        $names[] = $result->username;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)