freakT
freakT

Reputation: 11

php how to display values form array into ul li

I have an array like this:

$files = array(
    array(
        'name' => 'Detailed Brief - www.xyz.com.pdf',
        'size' => '1.4MB',
    ),
    array(
        'name' => 'Pure WordPress theme.zip',
        'size' => '735.9KB',
    ),
    array(
        'name' => 'Logotype.jpg',
        'size' => '94.7KB',
    ),
);

How can I display the information as follows:

ul - li 

Detailed Brief...- pdf(1.4mb)
Pure Wordpress... - zip(735.kb)
Logotype.jpg-(94,7kb)

Any ideas? I'm trying all the time with foreach but it's not working.

Upvotes: 0

Views: 40

Answers (2)

Lincoln Bergeson
Lincoln Bergeson

Reputation: 3451

The other answer is not quite what you're looking for. For each iteration of the loop, you want the filename, the file extension, and the file size:

<ul>
    <?php

    foreach ($files as $key => $file) {
        $f = pathinfo($file['name']);
        echo '<li>';
        echo $f['filename'].' - '.$f['extension'].'('.$file['size'].')';
        echo '</li>';
    }

    ?>
</ul>

Upvotes: 0

Rayann Nayran
Rayann Nayran

Reputation: 1135

It is simple:

<ul>
    <?php foreach ($files as $key => $file): ?>
        <li><?php echo $file['name'] . ' - ' . $file['size'] ?></li>
    <?php endforeach ?>
</ul>

Upvotes: 1

Related Questions