php - How to multiply two arrays of different length? -


I have two lines of different length:

  $ a = array (10, 20, 30, 40, 50); $ B = array (1, 2, 3);   

I want to multiply them (like $ c = array_mult ($ a, $ b) ), that little serial is repeated $ C should be 10, 40, 90, 40, 100 to:

  10 * 1 = 10 20 * 2 = 40 30 * 3 = 90 40 * 1 = 40 50 * 2 = 100   

Is there an inherent function in PHP to accomplish this task? How can I solve this problem efficiently?

There is no built-in function to do this; you can call it a foreach and Modules can be done easily with the operator, however:

  $ c = array (); $ Lane = count ($ B); Forex Currency ($ one $ key = & gt; $ value) {$ c [$ key] = $ value * $ b [($ key% $ lane]]; }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -