lundi 20 novembre 2017

php for loop random number generator issue

Task:

1.Use a for loop to build an array (randArray[]) with 50 random integers ranging from 0 - 100.

2.Use a while loop to build a new array (oddArray[]) with all the odd numbers in randArray[]

3.Use foreach loop to print all the odd numbers in oddArray[].

I just can't understand why this first step for loop doesn't work

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test1-1</title>
</head>
<body>
    <?php

    $randArray= [];
    $value = [];
    for ($randArray= 0; $randArray<= 50; $randArray++) {
            $value = rand(0, 100)
            $randArray[] = $value
        }
    endfor;

    echo ($randArray);



    ?>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire