如何在PHP中通过关联数组将两个值传递到一个变量中?

3
我有一个来自UberGallery的UberGallery.php文件,我正在使用它。
每个图像弹出窗口都会显示图片名称(例如 4488826 6f061c99ec b d),该名称取自于UberGallery.php。
  // Loop through array and add additional info
            foreach ($dirArray as $key => $image) {
                // Get files relative path
                $relativePath = $this->_rImgDir . '/' . $key;

                $galleryArray['images'][htmlentities(pathinfo($image['real_path'], PATHINFO_BASENAME))] = array(
                    'file_title'   => str_replace('_', ' ', pathinfo($image['real_path'], PATHINFO_FILENAME)),
                    'file_path'    => htmlentities($relativePath),
                    'thumb_path'   => $this->_createThumbnail($image['real_path'])
                );
            }

file_title 在上面的代码中影响了标题的更改。在 defaultGallery.php 中,图像显示如下:

 <?php if (!empty($images) && $stats['total_images'] > 0): ?>

        <ul id="galleryList" class="clearfix">

            <?php foreach ($images as $image): ?>
                <li><a href="<?php echo html_entity_decode($image['file_path']); ?>" title="<?php echo $image['file_title']; ?>" rel="<?php echo $relText; ?>"><img src="<?php echo $image['thumb_path']; ?>" alt="<?php echo $image['file_title']; ?>"/></a></li>
            <?php endforeach; ?>

        </ul>

    <?php else: ?>

        <p>No images found.</p>

    <?php endif; ?>

现在我想要在每个图像弹出窗口底部展示图像名称(4488826 6f061c99ec b d)和电子邮件地址(aaa@gmail.com)。

如果我在上面的file_titlestr_replace函数中更改以从csv文件中获取电子邮件地址,则什么也不会显示。gallery.csv有两个字段,如4488826 6f061c99ec b d aaa@gmail.com。我想将这两个值传递给file_title,以便它们出现在图像弹出窗口中。
$file_handle = fopen("gallery.csv", "r");

while (!feof($file_handle)) {

$lines_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);

            // Loop through array and add additional info
            foreach ($dirArray as $key => $image) {
                // Get files relative path
                $relativePath = $this->_rImgDir . '/' . $key;

                $galleryArray['images'][htmlentities(pathinfo($image['real_path'], PATHINFO_BASENAME))] = array(
                    'file_title'   => str_replace('_', $lines_of_text[1], pathinfo($image['real_path'], PATHINFO_FILENAME)),
                    'file_path'    => htmlentities($relativePath),
                    'thumb_path'   => $this->_createThumbnail($image['real_path'])
                );
            }

我应该如何将姓名和电子邮件传递给上述的 file_title 以获得所需结果?还是有其他方法可以做到这一点吗?
请帮我找出解决方案。
1个回答

1

try this one like

 $galleryArray['images'][htmlentities(pathinfo($image['real_path'], PATHINFO_BASENAME))] = array(
                'file_title'   => ' ',
                'file_path'    => htmlentities($relativePath),
                'thumb_path'   => $this->_createThumbnail($image['real_path'])
            );

如果我们将file_title保留为空,则什么也不会显示。我想展示问题中提到的两个字段。 - novice
@priya786:你有什么想法吗? - novice
你想要在标题的位置上同时显示姓名和电子邮件。 - priya786
哎呀,我想要更改位于图像弹出窗口底部的标题(请检查我提供的链接的演示),用图像名称和电子邮件替换。我正在尝试从CSV文件中获取这两个信息并显示在那里,但是无法做到。 - novice
@ priya786:你的回答不够符合 OP 的要求。 - kiran

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接