Php-framework-PHP array traversal sku attribute value pairing

Source: Internet
Author: User
{Code ...} 4 values:; because the key value is dynamic, therefore, an array traversal algorithm is required.
$ Skuattr = Array ('7' => Array ('6' => '22x33', '9' => '44x55 ',), '8' => Array ('12' => 'Big scale'), '9' => Array ('8' => 'metallic ', '13' => 'plastic ',), '16' => Array ('14' => 'Circular '));

Obtain 4 values.
;
;
;
;
Because the key value is dynamic, an array traversal algorithm is required.

Reply content:
$ Skuattr = Array ('7' => Array ('6' => '22x33', '9' => '44x55 ',), '8' => Array ('12' => 'Big scale'), '9' => Array ('8' => 'metallic ', '13' => 'plastic ',), '16' => Array ('14' => 'Circular '));

Obtain 4 values.
;
;
;
;
Because the key value is dynamic, an array traversal algorithm is required.

The principle is to require Cartesian product. A simple example is written.

phpFunction combineDika ($ data) {$ result = array (); foreach (array_shift ($ data) as $ k => $ item) {$ result [] = array ($ k => $ item);} foreach ($ data as $ k => $ v) {$ result2 = []; foreach ($ result as $ k1 =>$ item1) {foreach ($ v as $ k2 =>$ item2) {$ temp = $ item1; $ temp [$ k2] = $ item2; $ result2 [] = $ temp ;}}$ result = $ result2;} return $ result ;} $ skuattr = Array ('7' => Array ('6' => '22x33', '9' => '44x55 ',), '8' => Array ('12' => 'Big scale'), '9' => Array ('8' => 'metallic ', '13' => 'plastic ',), '16' => Array ('14' => 'Circular'); $ a = combineDika ($ skuattr ); print_r ($ );
phpArray ([0] => Array ([6] => 22x33 [12] => large trumpet [8] => metallic [14] => circle) [1] => Array ([6] => 22x33 [12] => small [13] => plastic [14] => Circular) [2] => Array ([9] => 44x55 [12] => large trumpet [8] => metallic [14] => circle) [3] => Array ([9] => 44x55 [12] => large trumpet [13] => plastic [14] => circle ))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.