我可以使用通配符取消设置 PHP $_SESSION{} 变量吗?
我可以用通配符取消设置吗?
我有一堆 $_SESSION 变量,它们都以相同的前缀开头。我可以使用通配符,而不是显式取消所有设置吗?
(前缀保持不变,但根据某些条件,后缀会有所不同,所以我宁愿不明确这样做)
$_SESSION['abc_1']
$_SESSION['abc_2']
$_SESSION['abc_fish']
$_SESSION['abc_xyz']
$SESSION['abc*']
Can I unset with wildcard?
I have a bunch of $_SESSION variables which all start with the same prefix. Rather than explicitly unset all, can I use a wildcard?
(the prefix remains the same, but depending on some conditions, the suffices vary, so I'd rathe not do it explicitly)
$_SESSION['abc_1']
$_SESSION['abc_2']
$_SESSION['abc_fish']
$_SESSION['abc_xyz']
$SESSION['abc*']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需循环数组并取消设置正确的数组即可...
Just loop through the array and unset the right one...
你可以尝试正确保存
像这样:
然后
you may try to save correctly
like this:
and then
我认为您不能使用通配符,但最简单的解决方案是您遍历会话数组并使用正则表达式检查键。如果匹配,则取消设置:)
I don't think you can use a wildcard, but the easiest solution would be for you to walk through the Session array and check the keys with a regex expression. If it matches, unset :)
你可以用类似的东西来做到这一点......
(我会使用 strpos 而不是 substr 因为它更快一点)
You could do this with something like ...
(I'd use strpos over substr because it's a bit faster)