php - How can I retrieve array of db results and make all possible combination of pairs? -
can me please:
this code:
<?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 $combination) { foreach ($flavs $flav) { $new_combinations[] = $combination .' - '. $flav; } } return icecream($flavs, $size - 1, $new_combinations); } $sql = ("select name 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 $outputs) { echo $outputs.'<br>'; } ?>
it giving me possible flavour combinations with:
$flavs = array('vanilla', 'strawberry', 'chocolate', 'stracciatella');
but need populate array $row['name'] database, when do:
$flavs = array($ice_all);
then gives me complete string of flavours. do wrong?
Comments
Post a Comment