Try
$myLastElement = end($yourArray);
Link to manual.
Or a PHP >= 7.3.0 solution:
(Which unlike
end(...)
, does not change internal iterator.)
$myLastElement = $yourArray[array_key_last($yourArray)];
Link to manual
More Related Contents:
- how can I print multiple services in this way
- Prevent creating duplicate entries in PHP
- Display multidimensional array in php
- Sum up array values [closed]
- Remove Duplicates in array php
- Is there any array function by which I can get the expected result? [duplicate]
- Convert php array to Javascript
- Convert a PHP object to an associative array
- PHP Sort a multidimensional array by element containing Y-m-d H:i:s date
- PHP in_array() / array_search() odd behaviour
- How to bind mysqli bind_param arguments dynamically in PHP?
- How to check whether an array is empty using PHP?
- php multi-dimensional array remove duplicate [duplicate]
- How to detect duplicate values in PHP array?
- Array as session variable
- Transpose 2d array, join second level with commas, and join first level with pipes
- MySQLi Bind Param with an array for IN [duplicate]
- Delete element from multidimensional-array based on value
- Search for PHP array element containing string [duplicate]
- Merge two arrays containing objects and remove duplicate values
- Deep recursive array of directory structure in PHP
- String contains any items in an array (case insensitive)
- Using value of a column as index in results using PDO
- Re-index numeric array keys [duplicate]
- Reverse array in php
- Sort an array of associative arrays by column value
- Find number which is greater than or equal to N in an array
- How does array_diff work?
- how to change the array key to start from 1 instead of 0 [duplicate]
- How to remove values from two arrays that have the same key and value?