Home Tutorial Php Phparray PHP Array Randomize

 
 

Share on Google+Share on Google+
PHP Array Randomize
Posted on: October 29, 2009 at 12:00 AM
Advertisement
This section demonstrates Learn how to use array_rand function in the php

  • array_rand() function is used to return the randomly one or more keys from the given array
  • By default it returns one key if no second argument is given.
  • If second argument is given other than 1 then it return keys in the form of array


PHP Array Randomize Example
<?php

    $arr3=array(12,23,45,67,89,99);
    foreach
($arr3 as $a)
     echo
" ".$a;

    $arr4
=array_rand($arr3);
    echo
"<br>key is $arr4";

    $arr4
=array_rand($arr3,2);
    echo
"<br>Now the key are ";
    foreach
($arr4 as $a)
     echo
" ".$a;
?>

                Output
           12 23 45 67 89 99
            key is 2
            Now the key are 0 2

Advertisement

Related Tags for PHP Array Randomize:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 29, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com