PHP数组返回
好的,功能:
function session_login_name($username) {
global $myDB;
global $config;
$query = "SELECT /* page == login, functions.php */id, username FROM members WHERE username = '".$username."' LIMIT 1";
$result = $myDB->Execute($query) or die(GetDbError($myDB->ErrorMsg()));
$nick_show = $result->Fields("username");
$nick_id = $result->Fields("id");
$arr = array($nick_show, $nick_id);
return $arr;
}
在下一个文件中我需要描述:
$_SESSION['userid'] = ; //user id
$_SESSION['username'] = ; //user name
我该怎么做? 如果问题不清楚,就说出来...... 哦,print_r ($arr) 给出: Array ( [0] => Zero [1] => 4 )
我已经尝试过(猜测),但这当然是不正确的:/
echo session_login_name($username[0]);
die();
Ok, function:
function session_login_name($username) {
global $myDB;
global $config;
$query = "SELECT /* page == login, functions.php */id, username FROM members WHERE username = '".$username."' LIMIT 1";
$result = $myDB->Execute($query) or die(GetDbError($myDB->ErrorMsg()));
$nick_show = $result->Fields("username");
$nick_id = $result->Fields("id");
$arr = array($nick_show, $nick_id);
return $arr;
}
In next file i need describe:
$_SESSION['userid'] = ; //user id
$_SESSION['username'] = ; //user name
How do I do that?
If question unclear, just say it...
Oh, and print_r ($arr) gives: Array ( [0] => zero [1] => 4 )
I have tried (guessed), but that of course isn't correct :/
echo session_login_name($username[0]);
die();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你说 print_r ($arr) 给出: Array ( [0] => Zero [1] => 4 ) 所以你只需要获取这些值并将它们分配给会话变量:
You said
print_r ($arr) gives: Array ( [0] => zero [1] => 4 )
so you just need to get those value and assign them to the session variables:好吧,你不能回显一个数组,它会在屏幕上打印 array()
你在哪里定义了 $username ?
简单地读取数组的值
well you cant echo an array it will print array() on the screen
where did you define $username ?
well simply read the values of the array