无法在多维数组中回显字符串但可以print_r
I've run into a weird problem, I can print_r()
my variable and it produces the following:
print_r($_SESSION['userdata']);
outputs: Array ( [0] => Array ( [id] => 1 [username] => admin [firstname] => carl [lastname] => wirkus [password] => password [admin] => 1 [staff] => 0 [tenant] => 0 [email] => test@test.com )
However when I try to echo the username with:
echo "You are currently logged in as: " . $_SESSION['userdata']['username'] . "<br>";
outputs: You are currently logged in as:
What have I done wrong?
我遇到了一个奇怪的问题,我可以 但是当我尝试用以下内容回显用户名时: p>
我做错了什么? p>
div> print_r() code>我的变量和 它产生以下内容: p>
print_r($ _ SESSION ['userdata']);
outputs:Array([0] =&gt; Array([id] =&gt; ; 1 [用户名] =&gt; admin [firstname] =&gt; carl [lastname] =&gt; wirkus [密码] =&gt;密码[admin] =&gt; 1 [staff] =&gt; 0 [租户] =&gt; 0 [email] =&gt; test@test.com)
code> pre>
echo“您当前登录时为:”。$ _SESSION ['userdata'] ['username']。“&lt; br&gt;”;
outputs:您当前登录为:
pre>
Looks closer at your print_r($_SESSION['userdata']);
. It's an array inside of an array. So you're not going deep enough to reach your values.
echo "You are currently logged in as: " . $_SESSION['userdata'][0]['username'] . "<br>";