Maximum Sum of Products of Two Arrays | Function that calculates maximum sum of products of two arrays ; Variable to store the sum of products of array elements ; length of the arrays ; Sorting both the arrays ; Traversing both the arrays and calculating sum of product ; Driver code
< ? php function maximumSOP ( & $ a , & $ b ) { $ sop = 0 ; $ n = sizeof ( $ a ) ; sort ( $ a ) ; sort ( $ b ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { $ sop = $ sop + ( $ a [ $ i ] * $ b [ $ i ] ) ; } return $ sop ; } $ A = array ( 1 , 2 , 3 ) ; $ B = array ( 4 , 5 , 1 ) ; echo maximumSOP ( $ A , $ B ) ; ? >