Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

foreach with array_chunk in php and with multiple arrays

I'm relatively new to php and I've been trying all day long to get this to work. I have a multiple array and want to echo each one in a specific format, and in groups. So i've gone through stackoverflow and found this help:

<? foreach(array_chunk($projetos, 6) as $curta ) { ?>


        <li style='display:block'>


                     <div class="film"> <?php echo $curta[0]['titulo']; ?></div>
                     <div class="film"> <?php echo $curta[1]['titulo']; ?></div>
                     <div class="film"> <?php echo $curta[2]['titulo']; ?></div>
                     <div class="film"> <?php echo $curta[3]['titulo']; ?></div>
                     <div class="film"> <?php echo $curta[4]['titulo']; ?></div>
                     <div class="film"> <?php echo $curta[5]['titulo']; ?></div>


             </li> 

      <? }; ?>

And this returns what I want but the last items of the array doesnt fill up to 6 and creates 2 extras empty divs and messes up the design.

This is a single example of the array i have:

<?php
 $projetos = array ( 

            "ugm" => array (
                    "id" => "ugm",
                    "titulo" => "Una Guerra Más",
                    "video" => "imagem",
                    "videoid" => "",
                    "height" => "$video_height_wide",
                    "sinopse" => "Um soldado moribundo deseja enviar sua última carta. Curta indisponível por exibição em festivais. Feito em parceria com a Universidad del Cine e LightBox Studios.",
                    "elenco" => "Ignacio J. Durruty - Rodrigo Soler - Ulisses Levanavicius - Aron Matschulat Aguiar",
                    "idioma" => "Inglês - Português",
                    "camera" => "Sony EX1",
                    "formato" => "HD",
                    "duracao" => "9'55''",
                    "ano" => "2012",
                    "tipo" => "Curta",
                    "credito" => "Direção - Edição - Produção - Roteiro",
                                 ), (...)

I want to be able to edit just one div that will be the master for the others... and using the implode I've read on another question but didn't worked to echo the strings I wanted..

Would please someone help out? thanks in advance!

like image 716
Aron Avatar asked Sep 16 '12 15:09

Aron


1 Answers

<?php foreach(array_chunk($projetos, 6) as $curta ) { ?>
    <li style='display:block'>
       <?php foreach($curta as $detail) { ?>
                 <div class="film"> <?php echo $detail['titulo']; ?></div>
       <?php } ?>
    </li> 
<? }; ?>
like image 113
Eugen Rieck Avatar answered Oct 14 '22 13:10

Eugen Rieck