Math Functions II Codeacademy PHP Example

Math Functions II Codeacademy PHP Example

Here is a correct example for “Math Functions II” from the PHP course.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<html>
    <p>
    <?php
    // Use rand() to print a random number to the screen
    print rand(0, 99);
    ?>
    </p>
    <p>
    <?php
    // Use your knowledge of strlen(), substr(), and rand() to
    // print a random character from your name to the screen.
    $name = "Cristi";
    $length = strlen($name)- 1;
    print substr($name, rand($length, $length - 1));
    ?>
    </p>
</html>

ONE COMMENT

  • victor says:02.06.2017

    The code above will only select between two random characters of the name instead of the whole characters, and also prints more than 1 character

Add a comment: