Professional Web Applications Themes

js to php -> random value from array - PHP Development

Hi all, Again I run into an issue (that's when you are new to php I guess) I need to convert this to php. Some of it is clear but I'm not sure about the random value and all, pls. let me know how to do this properly, without too many riscs function dlfileurl() { var UrlArray=new Array("org", "com", "net", "biz", "info", "org", "com", "net", "info"); var myurl=UrlArray[Math.floor(Math.random()*UrlArray.length)]; fullurl = "http://www.downloadurl." + myurl + "/product.zip"; window.open(fullurl) ; }...

  1. #1

    Default js to php -> random value from array

    Hi all,

    Again I run into an issue (that's when you are new to php I guess)

    I need to convert this to php.
    Some of it is clear but I'm not sure about the random value and all, pls.
    let me know how to do this properly, without too many riscs


    function dlfileurl()
    {
    var UrlArray=new Array("org", "com", "net", "biz", "info", "org", "com",
    "net", "info");
    var myurl=UrlArray[Math.floor(Math.random()*UrlArray.length)];
    fullurl = "http://www.downloadurl." + myurl + "/product.zip";
    window.open(fullurl) ;
    }





    Peter Guest

  2. #2

    Default Re: js to php -> random value from array

    > Again I run into an issue (that's when you are new to php I guess) 

    you are looking for something like this http://uk2.php.net/array_rand


    Peter Guest

  3. #3

    Default Re: js to php -> random value from array

    "Peter Van Hove" <net>
    kirjoitti viestissä:AJ_ne.109409$telenet-ops.be... 

    Random value from array php-style:

    <?php
    srand(mktime());
    // We have to seed the random number
    // generator with something, so we use
    // current time in seconds.

    $ar = array ("Meet", "the", "Flintsones", "have", "a", "yabbadabbadoo",
    "time");
    echo ($random_word = $ar[rand()%sizeof($ar)]);
    ?>


    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    com


    Kimmo Guest

  4. #4

    Default Re: js to php -> random value from array

    > <?php 

    you no longer need to seed the random number generator as long as you are
    using php 4.2 or greater. The following is taken from the rand doentation

    Note: As of PHP 4.2.0, there is no need to seed the random number generator
    with srand() or mt_srand() as this is now done automatically.


    Peter Guest

  5. #5

    Default Re: js to php -> random value from array

    "Peter" <com> kirjoitti
    viestissä:net... 
    >
    > you no longer need to seed the random number generator as long as you are
    > using php 4.2 or greater. The following is taken from the rand
    > doentation
    >
    > Note: As of PHP 4.2.0, there is no need to seed the random number
    > generator with srand() or mt_srand() as this is now done automatically.[/ref]


    Oh, I wasn't aware. Every day you learn something :)

    --
    "I am pro death penalty. That way people learn
    their lesson for the next time." -- Britney Spears

    com


    Kimmo Guest

Similar Threads

  1. a random und array problem
    By Ratw? in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: February 22nd, 06:12 AM
  2. random subarray from an array
    By Ante Perkovic in forum PHP Development
    Replies: 1
    Last Post: October 5th, 11:18 PM
  3. random array
    By Willem van Isselmuden in forum Macromedia Flash
    Replies: 0
    Last Post: September 21st, 09:49 PM
  4. Random Array values
    By mike in forum PHP Development
    Replies: 0
    Last Post: July 14th, 03:42 PM
  5. Problem with random array
    By noone in forum PHP Development
    Replies: 3
    Last Post: July 7th, 04:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139