使用PHP数组中的最后一项

使用PHP数组中的最后一项,php,arrays,image,content-management-system,gallery,Php,Arrays,Image,Content Management System,Gallery,您好,我正在使用作为一个新项目的后端,我已经将我的index.php设置为具有背景图像 现在,我希望用户能够在不删除其他图像的情况下更改“图库”中的图像,并且我希望加载“图库”中的最后一幅图像 这是驾驶舱走廊 我可以这样做: <?php foreach(gallery('Backgrounds') as $images): ?> <?php thumbnail($images["path"]) ?> <?php endforeach;?> 对不起

您好,我正在使用作为一个新项目的后端,我已经将我的
index.php
设置为具有背景图像

现在,我希望用户能够在不删除其他图像的情况下更改“图库”中的图像,并且我希望加载“图库”中的最后一幅图像

这是驾驶舱走廊

我可以这样做:

<?php foreach(gallery('Backgrounds') as $images): ?>

    <?php thumbnail($images["path"]) ?>

<?php endforeach;?>
对不起,我不是很精通PHP

干杯,
奥蒂斯·赖特。

你很接近了。首先,您必须获取数组的最后一个元素,然后获取它的值

<?php 
$img = end($images);
thumbnail($img["path"]);
?>

一种不那么优雅的方法是
$images[count($images)-1]['path']
,但是
end()
选项是最可靠的方法。
PHP Warning:  end() expects parameter 1 to be array, null given in /Users/username/Developer/Beardedweb/index.php on line 10
<?php 
$img = end($images);
thumbnail($img["path"]);
?>