Find three element from different three arrays such that a + b + c = sum | Function to check if there is an element from each array such that sum of the three elements is equal to given sum . ; Driver Code
< ? php function findTriplet ( $ a1 , $ a2 , $ a3 , $ n1 , $ n2 , $ n3 , $ sum ) { for ( $ i = 0 ; $ i < $ n1 ; $ i ++ ) for ( $ j = 0 ; $ j < $ n2 ; $ j ++ ) for ( $ k = 0 ; $ k < $ n3 ; $ k ++ ) if ( $ a1 [ $ i ] + $ a2 [ $ j ] + $ a3 [ $ k ] == $ sum ) return true ; return false ; } $ a1 = array ( 1 , 2 , 3 , 4 , 5 ) ; $ a2 = array ( 2 , 3 , 6 , 1 , 2 ) ; $ a3 = array ( 3 , 2 , 4 , 5 , 6 ) ; $ sum = 9 ; $ n1 = count ( $ a1 ) ; $ n2 = count ( $ a2 ) ; $ n3 = count ( $ a3 ) ; if ( findTriplet ( $ a1 , $ a2 , $ a3 , $ n1 , $ n2 , $ n3 , $ sum ) == true ) echo " Yes " ; else echo " No " ; ? >