Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use array_rand() function php.?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 114
    Comment on it

    What does array_rand() function in php.?

    The array_rand() function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key.

    Syntax of array_rand() function:

    array_rand(array,number)

    According to above syntax, there are two main Parameter of array_rand() 1- Array(this is used for specifing an array) 2- Number(Designates how many desultory keys to return)

    You can see below example of array_rand() function in php.

    <?php
    //here ColorName is a variable
    $ColorName=array("red","purple","blue","yellow","pink");
    //here call array_rand() function
    $result_;keys=array_rand($ColorName,4);
    
    echo $ColorName[$result_keys[0]]."<br>";
    echo $ColorName[$result_keys[1]]."<br>";
    echo $ColorName[$result_keys[2]]."<br>";
    echo $ColorName[$result_keys[3]];
    
    ?>
    

    Output of above code will be as following:-

    red
    purple
    blue
    yellow

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: