PHP:在For循环中创建唯一的变量 [英] PHP: Create Unique Variables In A For Loop

查看:161
本文介绍了PHP:在For循环中创建唯一的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在for循环中使用PHP创建唯一变量。我尝试了下面的代码,但没有成功:

  $ level_count = 6 

$ i = 1; $ i< = $ level_count; $ i ++){
$ level_ + $ i = array();
}

我想结束变量$ level_1,$ level_2,$ level_3,$ level_4,$ level_5和$ level_6。

解决方案

$ level_count = 6

为($ i = 1; $ i <= $ level_count; $ i ++){
$ l =level。 $ I;
$$ l = array();
}

但Zerkms是正确的...

  $ arr = array(array(),array(),array(),array(),array(),array()); 


I was wondering if it is possible to create unique variables in a for loop using PHP. I tried the following code but it didn't work:

$level_count = 6

for ($i=1; $i<=$level_count; $i++) {
    $level_ + $i = array();
}

I would like to end up with the variables $level_1, $level_2, $level_3, $level_4, $level_5 and $level_6. How would I achieve this?

解决方案

$level_count = 6

for ($i=1; $i<=$level_count; $i++) {
    $l = "level" . $i;
    $$l = array();
}

But Zerkms is right...

$arr = array(array(),array(),array(),array(),array(),array());

这篇关于PHP:在For循环中创建唯一的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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