dongqiabei7682 2012-11-26 03:23
浏览 50
已采纳

当我将它们放入变量时,会话变量变成了数组

I have a session for login data, and I am trying to take it and put it into a variable to shorten whenever I want to echo or use the ID, Username, or Email. What is happening is that now I have it in a variable, but when I echo it, it shows it in an array.

Here is my variable data.

$User = htmlentities(ucwords($_SESSION['user']['username']));
$Email = htmlentities($_SESSION['user']['email'], ENT_QUOTES, 'UTF-8');

If I echo any of these, it returns "Array".

EDIT

I fixed my solution by changing how I get my $_SESSION data, and using unset to get rid of the array. Now I can just do this,

$User  = $_SESSION['user']["username"];
$Email = $_SESSION['user']["email"]; 

Thank you for reminding me about how I'm even getting my session data in the first place =]

  • 写回答

1条回答 默认 最新

  • dongwen7380 2012-11-26 03:32
    关注

    If you are using classes, where you specify all your variables, maybe try this:

    $User  = $_SESSION['user']->username;
    echo $User;
    

    where user is your class and username is your variable WHen you add it to your session, you need to do soething like this:

        $_SESSION['user'] = new user();
        $_SESSION['user']->username= 'whatever value it is';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?