Ciao a tutti, quello che vorrei fare è costruire un questionario con risposte multiple, ho creato un DB ed un array associativo(chiave => valore) che raccoglie le risposte inserite nel DB. Voglio che le risposte siano ordinate in modo diverso ad ogni accesso, per fare questo ho usato la shuffle, tutto funziona come dovrebbe, ma il problema della shuffle è che non mantiene le chiavi originali (ho usato chiavi alfanumeriche), ma le sostituisce con chiavi numeriche 0, 1, 2... vi posto il codice che ho usato:
Codice PHP:
while($row = mysqli_fetch_array($selezione_db, MYSQLI_ASSOC))
{
$risposte=array(
'rispOK' => $row['rispOK'],
'rispNO1' => $row['rispNO1'],
'rispNO2' => $row['rispNO2'],
'rispNO3' => $row['rispNO3']
);
$shuffled_array = array();
$keys = array_keys($risposte);
shuffle($keys);
foreach ($keys as $key) {
$shuffled_array[$key] = $risposte[$key];
}
}
print_r($shuffled_array);
Quello che alla fine mi stampa è una cosa del genere:
Array ( [rispNO2] => No [rispOK] => Si...)
a me serve recuperare sia la chiave che il valore, quindi vorrei avere "rispOK" e "Si", naturalmente la chiave associata al suo effettivo valore, qualcuno mi può dare una mano per favore? Grazie