树枝长度不正确

时间:2018-03-21 07:34:20

标签: arrays twig

下面是我的包含子数组的类别数组,我想找到每个类别数组项的子数组的长度。

[category] => Array(
[0] => Array(
    [name] => Desktops
    [children] => Array(
        [0] => Array(
            [name] => PC
            [children3] => Array()
            [column] => 1
            [href] => http://192.168.0.101/user1/opc_laddylike3.0/upload/desktops/pc
            )
        [1] => Array(
            [name] => Mac
            [children3] => Array()
            [column] => 1
            [href] => http://192.168.0.101/user1/opc_laddylike3.0/upload/desktops/mac
            )
        )
    [column] => 1
    [href] => http://192.168.0.101/user1/opc_laddylike3.0/upload/desktops
    )
[1] => Array(
    [name] => Laptops & Notebooks
    [children] => Array(
        [0] => Array(
            [name] => Macs
            [children3] => Array()
            [column] => 1
            [href] => http://192.168.0.101/user1/opc_laddylike3.0/upload/laptop-notebook/macs
            )
        [1] => Array(
            [name] => Windows
            [children3] => Array()
            [column] => 1
            [href] => http://192.168.0.101/user1/opc_laddylike3.0/upload/laptop-notebook/windows
            )
        )
   [column] => 1
   [href] => http://192.168.0.101/user1/opc_laddylike3.0/upload/laptop-notebook
 )

我想找到类别数组的子项长度。如果我错了,请检查我的代码并提供帮助。

{% for category in categories %} 
{% if category.children %}
{% for n in 0..(category.children|length) %} 

这里我将所有数组项的category.children长度设为1。

提前致谢

0 个答案:

没有答案