请有人帮助我:
这是代码:
<?php
//...db connection code ...
function icecream($flavs, $size, $combinations = array()) {
if (empty($combinations))
{
$combinations = $flavs;
}
if ($size == 1)
{
return $combinations;
}
$new_combinations = array();
foreach ($combinations as $combination)
{
foreach ($flavs as $flav)
{
$new_combinations[] = $combination .' - '. $flav;
}
}
return icecream($flavs, $size - 1, $new_combinations);
}
$sql = ("SELECT name FROM eissorten");
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result))
{
$ice_all[] = $row['name'];
}
$ice_all = implode(', ',$ice_all);
$flavs = array('Vanilla', 'Strawberry', 'Chocolate', 'Stracciatella');
$output = icecream($flavs, 2);
foreach($output as $outputs)
{
echo $outputs.'<br>';
}
?>
它给了我所有可能的风味组合:
$flavs = array('Vanilla', 'Strawberry', 'Chocolate', 'Stracciatella');
但我需要在数据库中使用$ row [&#39; name&#39;]填充数组,所以当我这样做时:
$flavs = array($ice_all);
然后它给了我完整的口味。 我做错了什么?