Using PHP to "multiply" array values -


I'm a PHP novice and I'm sure I'm not using the right terms here.

I am creating an automated product data feed using a set of SKUs provided, but the feed needs separate entry for the size of the product and gender variation.

Is this an easy way to get:

  $ SKUs = array ('product1', 'product2', 'product3')   

and "multiply" each entry in the array with:

  $ gender = array ('M', 'F'); $ Size = array ('s', 'm', 'l', 'xl');   

So I end up with this result:

  $ feed = array ('Product1M-S', 'Product1M-M', 'Product1M - L ',' Product1M-XL ',' Product1F-S '...)    

< Pre> $ feed = array (); Foreign Currency ($ SKU as $ SKU) {foreach ($ gender as $ g) {foreach ($ s as $ s) {$ feed [] = $ sku $ G. '-'. $ S; }}} Print_r ($ feed);

Perhaps a simple array function is present, but it is easy to read, and is ready for future "easy" changes.

PS This is a great lecture with a similar problem:

PS2 as suggested by KA_lin , you do a function to do this However, I have not got the knowledge about array and product structure, and do not know if the size is always the same (S, L, X) for each product, if the arrays are always the same, Hardcoded inside the body can be done because KA_li N has been suggested. I just presented a linear solution, but you can easily upgrade your needs.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -