A voir également:
- Probleme php (commande rand)
- Alert php ✓ - Forum PHP
- Invite de commande - Guide
- Header php - Astuces et Solutions
- Undefined index php - Astuces et Solutions
- Commande terminal mac - Guide
1 réponse
voici une solution :)
<?php
function nombres_uniques($min, $max)
{
$tableau = range($min, $max);
$tab_ret = array();
$keys = array_rand($tableau, $max);
foreach($keys as $key)
$tab_ret[] = $tableau[$key];
return $tab_ret;
}
$tab=nombres_uniques(1,10);
//vos affectations
$a = $tab[0];
$b = $tab[1];
$c = $tab[2];
$d = $tab[3];
$e = $tab[4];
$f = $tab[5];
$g = $tab[6];
$h = $tab[7];
$i = $tab[8];
$j = $tab[9];
//juste pour l'affichage :p
$variables= array("a","b","c","d","e","f","g","h","i","j");
for($i=0;$i<10;$i++)
{
echo $variables[$i]." = ".$tab[$i] . "<BR>";
}
?>