Skip to content

Instantly share code, notes, and snippets.

@jeffersonchaves
Created June 29, 2021 14:36
Show Gist options
  • Save jeffersonchaves/0468c5baa1465377750c29b18cfe7efe to your computer and use it in GitHub Desktop.
Save jeffersonchaves/0468c5baa1465377750c29b18cfe7efe to your computer and use it in GitHub Desktop.
<?php
$numeroDaMega = [];
$numerosDaMegaOrdenados = [];
$todosDiferentes = true;
$contador = 0;
do {
$todosDiferentes = true;
$numeroDaMega[$contador] = mt_rand(1, 60);
foreach ($numeroDaMega as $numero => $value) {
if ($numeroDaMega[$contador] == $numeroDaMega[$numero] && $contador != $numero) {
$todosDiferentes = false;
}
}
if ($todosDiferentes)
$contador++;
} while ($contador < 6);
$numerosDaMegaOrdenados = $numeroDaMega;
sort($numerosDaMegaOrdenados);
echo "Os números sorteados na mega são: ";
foreach ($numerosDaMegaOrdenados as $numero => $value) {
echo "$numerosDaMegaOrdenados[$numero] ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment