1

我有以下 foreach 循环:

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

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

    <? endforeach ?>

我想在循环中添加另一个 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 ?>

但是这不起作用,我收到错误:

为 Foreach() 提供的参数无效

4

1 回答 1

4

好吧,我需要过期一点,但我想通了,我怀疑这对许多人会有帮助,但不管这是我需要做的:

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

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

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

    <? endforeach ?>

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

于 2015-05-05T20:10:28.940 回答