par
Visiteur2012 » 17 janv. 2012, 15:56
Bonjour,
Voici mon code :
Code : Tout sélectionner
$root = "images2";
$file = glob("$root/*.jpg", GLOB_BRACE);
$f01 = array_rand($file);
$f02 = array_rand($file);
$f03 = array_rand($file);
$f04 = array_rand($file);
Ca fonctionne bien, mais j'ai parfois des doublons lors de l'affichage des images.
J'ai bien compris qu'il fallait que je fasse une boucle, mais après je ne sais pas quoi faire...
j'étais parti sur ça (c'est long et ça ne marche pas) :
Code : Tout sélectionner
$root = "images2";
$file = glob("$root/*.jpg", GLOB_BRACE);
$f01 = array_rand($file);
$f02 = array_rand($file);
while ($file[$f02] == $file[$f01]){
unset ($file[$f02]);
$f02 = array_rand($file);
}
$f03 = array_rand($file);
while ($file[$f03] == $file[$f01]){
unset ($file[$f03]);
$f03 = array_rand($file);
}
while ($file[$f03] == $file[$f02]){
unset ($file[$f03]);
$f03 = array_rand($file);
}
$f04 = array_rand($file);
while ($file[$f04] == $file[$f01]){
unset ($file[$f04]);
$f04 = array_rand($file);
}
while ($file[$f04] == $file[$f02]){
unset ($file[$f04]);
$f04 = array_rand($file);
}
while ($file[$f04] == $file[$f03]){
unset ($file[$f04]);
$f04 = array_rand($file);
}
Pourriez-vous m'aider, car je tourne en rond depuis plusieurs jours sur ce problème,
Merci.

Bonjour,
Voici mon code :
[code]$root = "images2";
$file = glob("$root/*.jpg", GLOB_BRACE);
$f01 = array_rand($file);
$f02 = array_rand($file);
$f03 = array_rand($file);
$f04 = array_rand($file);[/code]
Ca fonctionne bien, mais j'ai parfois des doublons lors de l'affichage des images.
J'ai bien compris qu'il fallait que je fasse une boucle, mais après je ne sais pas quoi faire...
j'étais parti sur ça (c'est long et ça ne marche pas) :
[code]$root = "images2";
$file = glob("$root/*.jpg", GLOB_BRACE);
$f01 = array_rand($file);
$f02 = array_rand($file);
while ($file[$f02] == $file[$f01]){
unset ($file[$f02]);
$f02 = array_rand($file);
}
$f03 = array_rand($file);
while ($file[$f03] == $file[$f01]){
unset ($file[$f03]);
$f03 = array_rand($file);
}
while ($file[$f03] == $file[$f02]){
unset ($file[$f03]);
$f03 = array_rand($file);
}
$f04 = array_rand($file);
while ($file[$f04] == $file[$f01]){
unset ($file[$f04]);
$f04 = array_rand($file);
}
while ($file[$f04] == $file[$f02]){
unset ($file[$f04]);
$f04 = array_rand($file);
}
while ($file[$f04] == $file[$f03]){
unset ($file[$f04]);
$f04 = array_rand($file);
}[/code]
Pourriez-vous m'aider, car je tourne en rond depuis plusieurs jours sur ce problème,
Merci. :-)