开发者

PHP - Printing out values of arrays inside arrays

开发者 https://www.devze.com 2023-03-23 20:46 出处:网络
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.

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


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


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>';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号