How does php get the value of the penultimate element of the array?

how does php get the value of the penultimate element of the array?
such as the following array:

$arr=["apple","pear","banana","peach"];
Php
Mar.09,2021

$arr = ['apple','pear','banana','peach'];
print_r(array_slice($arr,-2,1));

echo $arr [count ($arr)-2];

you try this


$i = count($arr)-1;
echo $arr[$i];
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf858b-3186e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf858b-3186e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?