I want him to randomly pick 5 numbers from the string I entered and check them to see if they're even or odd This is the code I made but I don't want 0 included:
<?php
$s = array();
$tek =array();
$cift =array();
$tamsayi = array(1,2,3,4,5,6,7,8,9,10);
for( $i=0; $i<5; $i++){
$s [$i]= array_rand($tamsayi);
}
echo "Oluşturulan rastgele dizi : ";
foreach ($s as $el) {
echo $el;
}
for($j = 0; $j<5;$j++){
if($s[$j] % 2 == 0){
$cift[$j]=$s[$j];
}else{
$tek[$j]= $s[$j];
}
}
echo '<br>';
echo "Çift sayılar : ";
echo '<br>';
foreach ($cift as $eli) {
echo $eli;
echo '<br>';
}
echo "Tek sayılar : ";
echo '<br>';
foreach ($tek as $elin) {
echo $elin;
echo '<br>';
}
?>
Aucun commentaire:
Enregistrer un commentaire