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条)

报告相同问题?

悬赏问题

  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥20 spring boot集成mqtt的使用问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入
  • ¥15 mmo能不能做客户端怪物