PHP:如何获取数组的最后一个值

Jac*_*sas 2 php

我有以下 PHP 代码:

foreach ($resources as $resource)
{
    // Iterates on the found IDs
    //echo 'Name of field: ' . $resource . ' - Value: ' . $resource->attributes() . '<br />';
    echo '<tr><td>'.$resource->attributes().'</td></tr>';
}
Run Code Online (Sandbox Code Playgroud)

返回:

1
2
3
4
5
6
7
8
Run Code Online (Sandbox Code Playgroud)

我只想获取最后一项的值:8 我尝试使用:

echo end(end($resources->attributes()));
Run Code Online (Sandbox Code Playgroud)

但这返回:1

关于如何获得8值有什么想法吗?

谢谢

Ton*_*ark 6

尝试使用end()

end($resources)->attributes();
Run Code Online (Sandbox Code Playgroud)

这可能对你有帮助。