0

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.

3
  • 3
    Please edit your question to include your PHP code which is not working. Commented May 22, 2017 at 20:03
  • if (!$code) {print "Where's your code?";} Commented May 22, 2017 at 20:05
  • 3v4l.org/4ieXb Commented May 22, 2017 at 20:15

2 Answers 2

1

It is simple:

<ul>
    <?php foreach ($files as $key => $file): ?>
        <li><?php echo $file['name'] . ' - ' . $file['size'] ?></li>
    <?php endforeach ?>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.