如何在一个简单的数组中迭代所有可能的组合

时间:2015-06-16 23:58:14

标签: php

请帮我处理我的代码:

$a[1]='cloropil';
$a[2]='rodopayta';
$r=2;
$c=1;
$f= while($c<=$r){ echo $a[$c];;
$e = $c++ };
while($c<=$r){
echo $f;
$r++;
}
while($c<=$r){
echo $e;
$r++;
}

我希望它的输出如下:

$a[1]='cloropil';
$a[2]='rodopayta';
$r=2;
$c=1;
while($c<=$r){
 echo $a[$c];
   while($c<=$r){
    echo $a[$c];
    $c++;
   }
 $c++;
}

输出如何空白。 它甚至应该至少显示“cloropil”。 这甚至可能吗? 我希望显示如下内容:

cloropilcloropil cloropilrodopyta rodopytacloropil rodopytarodopyta

非常感谢你。

1 个答案:

答案 0 :(得分:0)

我认为这可能就是你要找的东西?:

float

给你:

<?php
$a[]='cloropil';
$a[]='rodopayta';

    // You first iterate over each
    for($i = 0; $i < count($a); $i++) 
        {
            // As you iterate through the first round, you iterate
            // again to match pairs but include the first iteration
            // value with this second 
            foreach($a as $val) 
                echo $a[$i].'=>'.$val.'<br />';
        }
?>
相关问题