Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Grabbing a random list of items, one per line?

    Hey guys,

    Sorry I am pretty stuck, what I want to do though is search these lines of data, line by line, and grab a random word from each line, until a reach a limit. So far I have this,


    foreach ($test as $tag){

    $newtag = $tag['Story'];



    $tags = implode(',', $newtag);

    }

    ^What this gives me is a result like this:



    computer, believe, see, hate

    computer, newegg

    person, walking





    Now how can I loop through these lines to grab a random word from each one, until I reach a limit, say 10. What I had in mind was a while loop, something like this,

    foreach ($test as $tag){

    $newtag = $tag['Story'];



    $tags = implode(',', $newtag);
    //$data = pr($tags);
    echo $tags;
    echo "<br />";

    }


    Any suggestions? Thanks.
    I am on my way. :)

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Try using array_rand().


  •  

    Posting Permissions

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