如何从多个阵列获得所有可能性?

时间:2016-02-23 03:10:33

标签: php

我需要五个数组来生成所有可能性。为简单起见,让我演示三个:

$material = array("cotton","polyester");
$size = array("small", "medium", "large");
$color = array("blue", "red", "green", "black");

我想提出一个包含所有可能性的多维数组:

cotton, small, blue
cotton, small, red
cotton, small, green
cotton, small, black
cotton, medium, blue
cotton, medium, red
cotton, medium, green
cotton, medium, black
cotton, large, blue
cotton, large, red
cotton, large, green
cotton, large, black
polyester, small, blue
polyester, small, red
polyester, small, green
polyester, small, black
polyester, medium, blue
polyester, medium, red
polyester, medium, green
polyester, medium, black
polyester, large, blue
polyester, large, red
polyester, large, green
polyester, large, black

我该怎么做?

2 个答案:

答案 0 :(得分:0)

试试这个。

  movieCall.enqueue(new Callback<MovieDataContainer>() {
            @Override
            public void onResponse(Call<MovieDataContainer> call, Response<MovieDataContainer> response) {
                if (response.isSuccess()) {
                    MovieDataContainer movieDataContainer = response.body();
                    Log.d("MainPresenterImpl",movieDataContainer.toString());
                }
            }

答案 1 :(得分:0)

这对我有用

    $material = array("cotton","polyester");
    $size = array("small", "medium", "large");
    $color = array("blue", "red", "green", "black");

    foreach ($material as $a) {

        foreach ($size as $b) {

            foreach ($color as $c) {

                $test = $a. ','. $b. ','.$c;
            }
        }
    }