How to structure a multi-array foreach/implode

Asked

Viewed 62 times

0

I’m having a problem with listing an array within a table, I’m using a function to capture information from a file. torrent and display in a table, however when files are inside a folder, the list keeps repeating the folder name.

inserir a descrição da imagem aqui

How could I get around this problem.

<table>
    <thead>
        <tr>
            <th scope='col'>ARQUIVOS</th>
            <th scope='col'>TAMANHO</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach($torrent->result['info']['files'] as $file) {
                echo "
                <tr>
                    <td class='announce-list-file'>" . implode('<tr><td>',$file['path']) . "</td>
                    <td class='announce-list-file'>" . formatSizeUnits($file['length']) . "</td>
                </tr>";
            }
        ?>
    </tbody>
</table>

1 answer

0

A suggestion would be to take only the last array value $file['path'] using the function end() that will always return the file name, so you will not have folders and subfolders in the table.

<table>
<thead>
    <tr>
        <th scope='col'>ARQUIVOS</th>
        <th scope='col'>TAMANHO</th>
    </tr>
</thead>
<tbody>
    <?php foreach($torrent->result['info']['files'] as $file) {      
        echo "
           <tr>
            <td class='announce-list-file'>".end($file['path']) ."</td>
            <td class='announce-list-file'>".$file['length']."</td>
        </tr>";
    }
    ?>
</tbody>

  • Thanks for answering, I tested but it did not work, it does not appear anything, the if is interpreting as false and is not displaying anything, from a look at my other question, I added the source at the end of the question, if you want to give a deeper look. https://answall.com/questions/352972/lista-pasta-e-subpastas-em-um-foreach-php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.