BigJobbies
BigJobbies

Reputation: 4353

PHP - Printing out values of arrays inside arrays

I have a system that inputs multiple images via a backend script ... i want to be able to echo out the images into a list on the frontend so i can manipulate them.

Im not exactly sure how i would do this using a loop.

In my PHP im viewing the contents of the array using the following:

<?php print_r($node->rotator['und']); ?>

When it prints out, its giving me the following information

Array (
    [0] => Array ( [fid] => 4 [alt] => [title] => [uid] => 1 [filename] => fredmanhhh.jpeg [uri] => public://fredmahjk.jpeg [filemime] => image/jpeg [filesize] => 108646 [status] => 1 [timestamp] => 1311781185 [rdf_mapping] => Array ( ) ) 
    [1] => Array ( [fid] => 6 [alt] => [title] => [uid] => 1 [filename] => 92_mr_t_snickers1.jpeg [uri] => public://92_mr_t_snickers1_1.jpeg [filemime] => image/jpeg [filesize] => 475757 [status] => 1 [timestamp] => 1311785879 [rdf_mapping] => Array ( ) ) 
)

What i need to do with a loop is extract the [filename] and add that inside the list tag for each image thats been uploaded.

If anyone could help me, that would be grand.

Cheers

Upvotes: 2

Views: 150

Answers (2)

cwallenpoole
cwallenpoole

Reputation: 82088

Well, basically what you're trying to do is loop through all of the arrays and then output them:

foreach( $node->rotator['und'] as $und ) 
   echo '<li><img src="' . $und['filename'] . '"/></li>';

To store them for later at the same time:

$undFiles = array();

foreach( $node->rotator['und'] as $und ) 
{
   $undFiles[] = $und['filename'];
   echo '<li><img src="' . $und['filename'] . '"/></li>';
}

Upvotes: 0

David Nguyen
David Nguyen

Reputation: 8508

foreach($node->rotator['und'] as $row){
    echo '<li><img src="' . $row['filename'] . '"/></li>';
}

Upvotes: 2

Related Questions