简体   繁体   中英

Nested foreach array loop in PHP

I have for each loop return an array

<?php foreach( get_uf_repeater( 'clients' ) as $document_files ): extract( $document_files ) ?>
<div class="ui-grid-a my-breakpoint">
    <div class="ui-block-a"><a href="<?PHP echo $website_url ?>" target="_blank"><img src="<?php echo $project_image ?>" title="Project image" /><div><?php echo $project_detailes ?></div></a></div>
    <div class="ui-block-b"><a href="<?PHP echo $website_url ?>" target="_blank"><img src="<?php echo $project_image ?>" title="Project image" /><div><?php echo $project_detailes ?></div></a></div>
</div>
<?php endforeach ?>

how can i jump to the next array for the second line "" instead of displaying the same of the first one, I assume I need nested loop but didnt know how do it exactly.

You could use array_chunk

<?php foreach (array_chunk(get_uf_repeater( 'clients' ), 2, true) as $array) { ?>
    <div class="ui-grid-a my-breakpoint">
        <?php foreach($array as $document_files) { ?>
            <?php extract( $document_files ); ?>
            <div class="ui-block-a"><a href="<?PHP echo $website_url ?>" target="_blank"><img src="<?php echo $project_image ?>" title="Project image" /><div><?php echo $project_detailes ?></div></a></div>
        <?php } ?>
    </div>
<?php } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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