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 關注
- 86 瀏覽
添加回答
舉報