dongyaoxiu6244 2016-09-28 08:53
浏览 52
已采纳

从URL中选择PHP数组

I have coded a internal messenger system for the company I work for and I am trying to make things easier for myself by making a admin panel for this so it can control the usernames, passwords and groups.

Basically I am trying to select a user from the array using a url ?user=username which will then return the user information and allow it to be changed. The problem I am having is to get the url to select the username in the array.

The array is basic:

$users = array(
    '0' => array(
        'username' => 'test',
        'password' => 'test123',
        'group' => 'office',
    ),
  • 写回答

4条回答 默认 最新

  • douju2474 2016-09-28 08:58
    关注

    Like this?:

    <?php
    
    // get username from URL (GET METHOD)
    $username=$_GET["username"];
    
    // $users has all the info
    
    foreach ($users as $u) {
      // find the target user
      if ($u["username"] == $username) {
          // do something with $u
          var_dump($u);
      }
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题