Find first element on left side that is greater than arr [ i ] .
for ( $ j = $ i - 1 ; $ j >= 0 ; $ j -- ) { if ( $ arr [ $ i ] < $ arr [ $ j ] ) { echo ( $ arr [ $ j ] ) ; echo ( " , ▁ " ) ; break ; } }