Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何在速度上将一个序列拆分为多个序列?_Apache_Foreach_Velocity - Fatal编程技术网

Apache 如何在速度上将一个序列拆分为多个序列?

Apache 如何在速度上将一个序列拆分为多个序列?,apache,foreach,velocity,Apache,Foreach,Velocity,我有这个阵列: seq = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] 我想把这个序列分成两个有四个元素的序列,如下所示: a b c d e f g h 我尝试使用两个foreach来拆分列表,一个用于对四个元素进行分组,另一个用于获取元素。但它不起作用: #foreach( $groupOfFour in $allProducts ) #if( $velocityCount == 4 ) <ul&g

我有这个阵列:

seq = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
我想把这个序列分成两个有四个元素的序列,如下所示:

a b c d 
e f g h
我尝试使用两个foreach来拆分列表,一个用于对四个元素进行分组,另一个用于获取元素。但它不起作用:

#foreach( $groupOfFour in $allProducts )
    #if( $velocityCount == 4 )
        <ul>
        #foreach( $product in $groupOfFour )
            <ul>
                <li>$product</li>
            </ul>
        </ul>
    #end
#end
#foreach($allProducts中的groupofffour)
#如果($velocityCount==4)
    #foreach($GroupOffFour中的产品)
    • $product
#结束 #结束
这看起来非常接近

在Velocity 1.7+中,使用$foreach.index(基于0)、$foreach.count(基于1)、$foreach.first和$foreach.last()

    #foreach($product中的$allProducts) #如果($foreach.index%4==0) #如果(!$foreach.first)
#结束
    #结束 $product #如果($foreach.last)
#结束 #结束
<ul>
#foreach( $product in $allProducts )
    #if( $foreach.index %4 == 0 )
        #if( !$foreach.first )
          </ul>
        #end
        <ul>
    #end
    $product
    #if( $foreach.last )
        </ul>
    #end
#end
</ul>