Program for dot product and cross product of two vectors | PHP implementation for dot product and cross product of two vector . ; Function that return dot product of two vector array . ; Loop for calculate cot product ; Function to find cross product of two vector array . ; Driver Code ; dotproduct function call ; crossproduct function call ; Loop that print cross product of two vector array .
< ? php $ n = 3 ; function dotproduct ( $ vect_A , $ vect_B ) { global $ n ; $ product = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ product = $ product + $ vect_A [ $ i ] * $ vect_B [ $ i ] ; return $ product ; } function crossproduct ( $ vect_A , $ vect_B , $ cross_P ) { $ cross_P [ 0 ] = $ vect_A [ 1 ] * $ vect_B [ 2 ] - $ vect_A [ 2 ] * $ vect_B [ 1 ] ; $ cross_P [ 1 ] = $ vect_A [ 2 ] * $ vect_B [ 0 ] - $ vect_A [ 0 ] * $ vect_B [ 2 ] ; $ cross_P [ 2 ] = $ vect_A [ 0 ] * $ vect_B [ 1 ] - $ vect_A [ 1 ] * $ vect_B [ 0 ] ; return $ cross_P ; } $ vect_A = array ( 3 , -5 , 4 ) ; $ vect_B = array ( 2 , 6 , 5 ) ; $ cross_P = array_fill ( 0 , $ n , 0 ) ; echo " Dot ▁ product : " ; echo dotproduct ( $ vect_A , $ vect_B ) ; echo " Cross product : " $ cross_P = crossproduct ( $ vect_A , $ vect_B , $ cross_P ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) echo $ cross_P [ $ i ] . " ▁ " ; ? >