相关疑难解决方法(0)

PHP每个循环在数组中更深一层

我正在尝试遍历一个数组,每次都向另一个数组添加一个新级别.让我举例说明 - 变量$ arr的值每次都不同

$arr = array("1","5","6");
Run Code Online (Sandbox Code Playgroud)

循环

$index[$arr[0]];
Run Code Online (Sandbox Code Playgroud)

循环

$index["1"][$arr[1]]  // "1" since this key was filled in by the previous loop, continuing with a new key
Run Code Online (Sandbox Code Playgroud)

循环

$index["1"]["5"][$arr[2]] // same as previous loop
Run Code Online (Sandbox Code Playgroud)

- 完成所有$ arr的项目,结果是$ index ["1"] ["5"] ["6"] -

问题是我不知道$arr数组包含多少值.然后,我不知道如何继续,例如,$index["1"]当第一个值$arr已经循环到下一个数组级别时(换句话说:添加另一个键).

任何人?

php arrays loops nested

1
推荐指数
1
解决办法
3445
查看次数

标签 统计

arrays ×1

loops ×1

nested ×1

php ×1