Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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
如何从数组中的一个条目循环到最后?细枝/php_Php_Loops_Twig - Fatal编程技术网

如何从数组中的一个条目循环到最后?细枝/php

如何从数组中的一个条目循环到最后?细枝/php,php,loops,twig,Php,Loops,Twig,我要求对一个数组进行循环,如下所示: Array ( [0] => 215950741 [1] => 3900 [2] => 10527160 [3] => 2873 ... [44] => N~~~~ [45] => N~~~~ [46] => historico_estados [47] => 18/10/2018 16:03:09~10~Solicitada~ARANJUEZ~0

我要求对一个数组进行循环,如下所示:

Array
(
    [0] => 215950741
    [1] => 3900
    [2] => 10527160
    [3] => 2873
...
    [44] => N~~~~
    [45] => N~~~~
    [46] => historico_estados
    [47] => 18/10/2018 16:03:09~10~Solicitada~ARANJUEZ~0~2873~   ~
    [48] => 18/10/2018 16:06:42~13~Aceptada~ARANJUEZ~0~2873~   ~
    [49] => 18/10/2018 18:15:49~3~Tránsito~SANTANDER~0~3900~   ~
    [50] => 18/10/2018 22:28:49~3~Tránsito~PLATVITORIA~0~9001~   ~
    [51] => 19/10/2018 04:19:33~3~Tránsito~PLATMADRID~0~9028~   ~
    [52] => 19/10/2018 08:15:53~2~Reparto~ARANJUEZ~0~2873~   ~
    [53] => 19/10/2018 09:37:00~1~Entregado~RECEPTOR~0~2873~   ~
)

我需要从数组的第46条循环到最后,我尝试过做一些事情,但根本不起作用,而且我只能在Twig中完成,所以我有点迷路了。我可以使用twig的
last
功能获取数组的最后一个条目。。但是找不到可以获取最后条目的内容。

在twig中,您可以使用for循环来完成此操作:

{% for i in 44..array|length-1 %}
    {{ array[i] }}
{% endfor %}
请参见示例输出

此外(感谢),您可以通过访问。从文档中:

因此,您可以完成以下操作:

{% for item in array[44:] %}
   {{ item }}
{% endfor %}

请参见此示例输出。

在twig中,您可以使用for循环完成此操作:

{% for i in 44..array|length-1 %}
    {{ array[i] }}
{% endfor %}
请参见示例输出

此外(感谢),您可以通过访问。从文档中:

因此,您可以完成以下操作:

{% for item in array[44:] %}
   {{ item }}
{% endfor %}

请参阅此示例输出。

您可以使用
循环中的
变量
for

{% for el in elems %}
    {% if loop.index0 > 45 %}
        {# do some stuff #}
    {% endif %}
{% endfor %}

您可以使用
循环
变量内部
for

{% for el in elems %}
    {% if loop.index0 > 45 %}
        {# do some stuff #}
    {% endif %}
{% endfor %}

我想OP需要的是twig,而不是PHP。这就是重点,我可以在PHP上完成,但我不知道如何在twig中复制它。我已经看过了twig的文档但是@wiitohzjeh我已经更新了我的帖子(我很抱歉,当我浏览它的时候,我把它读成PHP)。谢谢,我终于得到了它:我想OP需要它在twig中,而不是PHP中。这就是重点,我可以在PHP上做,但我不知道如何在twig中复制它。我已经看过了twig的文档但是@wiitohzjeh我已经更新了我的帖子(很抱歉,当我浏览它时,我把它读成PHP)。谢谢,我终于得到了它:数组中I的
{%46:]}
?数组中I的
{%46:]}的可能重复