如何操作数组
所以,我有这个数组:
Array ( [idservice] => 3 [level0] => 0.35 ) Array ( [idservice] => 3 [level0] =>
0.35 ) Array ( [idservice] => 2 [level0] => 6.00 ) Array ( [idservice] => 2 [level0]
=> 6.00 ) Array ( [idservice] => 100 [level0] => 20.00 ) Array ( [idservice] => 100
[level0] => 20.00 )
我需要将 3 作为变量添加一个前缀,使其成为 $id_3 并将 level0 设置为变量的值,就像这样
$id_3 = 0.35
,我必须对所有数组执行此操作,所以最后我会问:
$id_3 = 0.35
$id_2 = 2.00
$id_100 = 6.00
这可能吗? o
和 i
需要 foreach
类型的语句,这样我就可以一次获取所有变量。
So, I have this array:
Array ( [idservice] => 3 [level0] => 0.35 ) Array ( [idservice] => 3 [level0] =>
0.35 ) Array ( [idservice] => 2 [level0] => 6.00 ) Array ( [idservice] => 2 [level0]
=> 6.00 ) Array ( [idservice] => 100 [level0] => 20.00 ) Array ( [idservice] => 100
[level0] => 20.00 )
i need to make the 3 as a variable add a prefix to it to make it $id_3 and set the level0 as the value of the variable, like this
$id_3 = 0.35
and I have to do this for all the arrays, so that in the end I would have :
$id_3 = 0.35
$id_2 = 2.00
$id_100 = 6.00
is that at all possible?o
and i
need foreach
kind of statement so that, I can get all the variables at one time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该做你想要的:
将导致:
This should do what you want:
will result in:
您可以使用
extract
函数。以下内容。
您可以使用
EXTR_PREFIX_ALL
参数在每个变量名称之前添加id
前缀。请参阅文档此处
you could use the
extract
function.Something on the following lines.
You could use the
EXTR_PREFIX_ALL
parameter to prefixid
before every variable name.See documentation here