PHP数组赋值给变量 [英] PHP Assign array to variables

查看:183
本文介绍了PHP数组赋值给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如果我的记忆是错误的,但是当我最后一次使用PHP(年前),我依稀记得做这样的事情:

  $ firstVariable,$ secondVariable =爆炸('','富酒吧');

请注意,上面是不正确的语法,但在这个例子中,将分配'富'到$ firstVariable,和'酒吧'到$ secondVariable。

什么是正确的语法呢?

感谢。


解决方案

 列表($ firstVar,$ secondVar)=爆炸('','富酒吧');  

列表()是你所追求的。

I'm not sure if my memory is wrong, but when I last used PHP (years ago), I vaguely remember doing something like this:

$firstVariable, $secondVariable = explode(' ', 'Foo Bar');

Note that the above is incorrect syntax, however in this example it would assign 'Foo' to $firstVariable, and 'Bar' to $secondVariable.

What is the correct syntax for this?

Thanks.

解决方案

list($firstVar, $secondVar) = explode(' ', 'Foo Bar');

list() is what you are after.

这篇关于PHP数组赋值给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆