【发布时间】:2020-05-02 23:06:38
【问题描述】:
我有一个这样的输出数组:
Array
(
[0] => Array
(
[item] => null
[count] => 0
[child] => Array
(
[Dagadu Bocah] => Array
(
[item] => Dagadu Bocah
[count] => 47
[child] => Array
(
[HirukPikuk] => Array
(
[item] => HirukPikuk
[count] => 5
[child] => Array
(
[DGD] => Array
(
[item] => DGD
[count] => 1
[child] =>
)
)
)
[DGD] => Array
(
[item] => DGD
[count] => 5
[child] => Array
(
[Malioboroman] => Array
(
[item] => Malioboroman
[count] => 1
[child] =>
)
)
)
[Malioboroman] => Array
(
[item] => Malioboroman
[count] => 2
[child] =>
)
)
)
)
)
)
在我的期望中,我可以使用我之前在this question 中询问的循环,方法是重复删除某些数组以消除数组的不同部分,该数组是一个位于包含三个数组的数组之上的数组项目即'item','count'和'child'以及如何从上面的数组中生成这样的数组?
Array
(
[0] => Array
(
[item] => null
[count] => 0
[child] => Array
(
[0] => Array
(
[item] => Dagadu Bocah
[count] => 47
[child] => Array
(
[0] => Array
(
[item] => HirukPikuk
[count] => 5
[child] => Array
(
[0] => Array
(
[item] => DGD
[count] => 1
[child] =>
)
)
)
[1] => Array
(
[item] => DGD
[count] => 5
[child] => Array
(
[Malioboroman] => Array
(
[item] => Malioboroman
[count] => 1
[child] =>
)
)
)
[2] => Array
(
[item] => Malioboroman
[count] => 2
[child] =>
)
)
)
)
)
)
【问题讨论】:
-
这里没有问题。
-
如果对数组使用带有引用参数的递归函数,当达到要取消设置的级别时,会影响原始数组。
-
等等,我编辑我的问题
-
你的词组好像没完没了。您能否将段落拆分为较短的短语,以便我们更好地理解您的要求?
-
另外,请不要发布
print_r的输出,而是以PHP 语法发布您的输入和预期输出。
标签: php arrays multidimensional-array unset