How to get the last element of an array in PHP without removing it?
Hello! I'm a beginner in PHP and encountered a problem when working with arrays. I need to get the last element of an array, but without removing it from the array.
Here's the situation: I have an array with user data that I get from the database. I need to display the last added user on the page, but keep the entire array for further processing (for example, to display all users in a table).
The problem is that I know the `array_pop()` function, which perfectly gets the last element, but it removes it from the original array. This doesn't work for me because the array loses the element afterward.
Here's an example of my code:
```php
No answers yet.
Log in to leave an answer
Blogs