Front and Back Search in unsorted array | PHP program to implement front and back search ; Start searching from both ends ; Keep searching while two indexes do not cross . ; Driver Code
< ? php function search ( $ arr , $ n , $ x ) { $ front = 0 ; $ back = $ n - 1 ; while ( $ front <= $ back ) { if ( $ arr [ $ front ] == $ x $ arr [ $ back ] == $ x ) return true ; $ front ++ ; $ back -- ; } return false ; } $ arr = array ( 10 , 20 , 80 , 30 , 60 , 50 , 110 , 100 , 130 , 170 ) ; $ x = 130 ; $ n = sizeof ( $ arr ) ; if ( search ( $ arr , $ n , $ x ) ) echo " Yes " ; else echo " No " ; ? >