# Php multi-array combination arrangement algorithm

Source: Internet
Author: User
Evaluate the php multi-array combination arrangement algorithm to simulate four arrays:
\$ List ['A'] = array (1, 2, 3 );
\$ List ['B'] = array (4, 5, 6 );
\$ List ['c'] = array (7, 8, 9 );

Combination of requirements:, 68, 69

Algorithm

Reply to discussion (solution)

A piece of code is displayed on the Internet:

` getsulie(\$list,\$v,1);            }                     }        function getsulie(\$list,\$content,\$deep){            \$i=0;            if(\$deep>count(\$list)){                return;            }            foreach(\$list as \$k=>\$v){                if(\$i==\$deep){                    foreach(\$list[\$k] as \$vv){                        \$vv = \$content.\$vv;                        if(\$deep==count(\$list)-1){                            echo \$vv."";                        }else {                            \$this->getsulie(\$list,\$vv,\$deep+1);                        }                    }                    break;                }                \$i++;            }            return;        }    }    \$s = new sufa();    \$s->main();     ?>`

But this is not the same.

Recursion is not easy to use. please kindly advise

`\$list['a'] = array (1,2,3);\$list['b'] = array (4,5,6);\$list['c'] = array (7,8,9);foreach(\$list as \$key=>\$row) {  unset(\$list[\$key]);  foreach(\$row as \$col) {    foreach(\$list as \$r)      foreach(\$r as \$v) \$res[] = \$col . \$v;  }}echo join(',', \$res);`
, 69

`\$list['a'] = array (1,2,3);\$list['b'] = array (4,5,6);\$list['c'] = array (7,8,9);foreach(\$list as \$key=>\$row) {  unset(\$list[\$key]);  foreach(\$row as \$col) {    foreach(\$list as \$r)      foreach(\$r as \$v) \$res[] = \$col . \$v;  }}echo join(',', \$res);`
, 69

A positive solution, how can we implement a combination of three numbers, such

`\$list['a'] = array (1,2,3);\$list['b'] = array (4,5,6);\$list['c'] = array (7,8,9);\$list['d'] = array (10,11,12);`

Finally, you need to get:
147,148,149,157,158,159,167,168,169,247,248,249,257,258,259,267,268,269,347,348,349,357,358,359,367,368,369

`\$list['a'] = array (1,2,3);\$list['b'] = array (4,5,6);\$list['c'] = array (7,8,9);foreach(\$list as \$key=>\$row) {  unset(\$list[\$key]);  foreach(\$row as \$col) {    foreach(\$list as \$r)      foreach(\$r as \$v) \$res[] = \$col . \$v;  }}echo join(',', \$res);`
, 69

I wrote an error and wrote an array,
`\$list['a'] = array (1,2,3);\$list['b'] = array (4,5,6);\$list['c'] = array (7,8,9);`

Finally, you need to get:
147,148,149,157,158,159,167,168,169,247,248,249,257,258,259,267,268,269,347,348,349,357,358,359,367,368,369

I thought you were in urgent need of solving problems at work. I didn't think you were studying algorithms.
From an algorithm perspective, your two questions should be: perform Cartesian product operations on the result of the combination of the original data (C (m, n ).
The code will not be pasted. you can find multiple versions in the essence area.

I thought you were in urgent need of solving problems at work. I didn't think you were studying algorithms.
From an algorithm perspective, your two questions should be: perform Cartesian product operations on the result of the combination of the original data (C (m, n ).
The code will not be pasted. you can find multiple versions in the essence area.

Thank you.
Related Keywords:

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.