compare elements and return last duplicate and its index
for ( $ i = $ n - 1 ; $ i > 0 ; $ i -- ) { if ( $ arr [ $ i ] == $ arr [ $ i - 1 ] ) { echo " Last ▁ index : " , $ i , " STRNEWLINE " ; echo " Last ▁ duplicate ▁ item : " , $ arr [ $ i ] ; return ; } }