1 回答
TA贡献1831条经验 获得超10个赞
如所见,您希望通过以下方式拆分2 strings into chars并获得所有组合2 chars:第一种形式blank1和第二种形式blank2。
而不是手动进行组合使用常规for-loop.
$result = array();
for ($i = 0; $i < count($blank1); $i++)
{
for ($j = 0; $j < count($blank2); $j++)
{
//set combination
$aux = $blank1[$i].$blank2[$j];
array_push($result, $aux);
}
}
//result should be populated with combination of 2
//just list it and use as need
for ($i = 0; $i < count($result); $i++)
{
echo $result[$i];
}
//same with stored or checking on db : use loops
对于多个组合,使用更多的嵌套循环,
例如:[blank1][blank2][blank1]- 3 组合
$result = array();
//1
for ($i = 0; $i < count($blank1); $i++)
{
//2
for ($j = 0; $j < count($blank2); $j++)
{
//3
for ($k = 0; $k < count($blank1); $k++)
{
//set combination
$aux = $blank1[$i].$blank2[$j].$blank1[$k];
array_push($result, $aux);
}
}
}
与您想要的任何数字相同!如果要写很多循环会有点烦人但请注意while can be used with an adequate algorithm。但目前只需尽可能简单并获得所需的结果。
- 1 回答
- 0 关注
- 114 浏览
添加回答
举报
