简体   繁体   English

使用 short_open_tags 在 Foreach 循环中嵌套 Foreach 循环

[英]Nesting Foreach loop inside Foreach loop using short_open_tags

I have the following foreach loop:我有以下 foreach 循环:

<?php
    $fields = CFS()->get('list-item-field');
?>
    <? foreach ($fields as $field) : ?>

        <?= $field['list-item-title'] ?>    

    <? endforeach ?>

And I would like to add another foreach inside the loop, like so:我想在循环中添加另一个 foreach,如下所示:

<?php
    $fields = CFS()->get('item-field');
?>
    <? foreach ($fields as $field) : ?>

        <?= $field['list-item-title'] ?>

        <?php
            $values = CFS()->get('color');
        ?>
            <? foreach ($values as $value => $label) : ?>
                <? echo $value ; ?>
            <? endforeach ?>

    <? endforeach ?>

However this doesn't work, and I get the error:但是这不起作用,我收到错误消息:

Invalid Argument Supplied For Foreach()为 Foreach() 提供的参数无效

Alright I needed to expirement a bit but I figured it out, I doubt this will be helpful to many but regardless here's what I needed to do:好吧,我需要到期,但我想通了,我怀疑这对许多人有帮助,但不管我需要做什么:

<?php
    $fields = CFS()->get('item-field');
?>
    <? foreach ($fields as $field) : ?>

        <?= $field['list-item-title'] ?>

        <? foreach ($field['color'] as $colors => $label) :?>
            <? echo $colors ; ?>
        <? endforeach ?>

    <? endforeach ?>

This post helped: http://customfieldsuite.com/forums/questions/925/loop-within-a-loop这篇文章有帮助: http : //customfieldsuite.com/forums/questions/925/loop-within-a-loop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM