php random array problem

  • jamesbond
  • Novice
  • Novice
  • jamesbond
  • Posts: 23

Post 3+ Months Ago

I have a html wordList imported as a array and and 2 for loops for col and rows. my problem is i need to get the function to grab a random letter from the wordList array and put a random letter from the wordlist in each cell
Code: [ Select ]
function addFoils(){
global $board, $boardData;
for($row = 0; $row < $boardData["height"]; $row++){// for my rows
 for ($col = 0; $col < $boardData["width"]; $col++){//for my cols
  if($board[$row][$col] == "."){//.means to add letter to the cell
   $newLet = $_REQUEST["wordList"];//array from html wordlist
    $newLet = strtoupper($newLet);//convert to upper case
     $firstLetter = substr($newLet,0,1);//picks out first letter
      $board[$row][$col] = str_shuffle($firstLetter);//shuffles wordlist
            }
        }
    }
}
  1. function addFoils(){
  2. global $board, $boardData;
  3. for($row = 0; $row < $boardData["height"]; $row++){// for my rows
  4.  for ($col = 0; $col < $boardData["width"]; $col++){//for my cols
  5.   if($board[$row][$col] == "."){//.means to add letter to the cell
  6.    $newLet = $_REQUEST["wordList"];//array from html wordlist
  7.     $newLet = strtoupper($newLet);//convert to upper case
  8.      $firstLetter = substr($newLet,0,1);//picks out first letter
  9.       $board[$row][$col] = str_shuffle($firstLetter);//shuffles wordlist
  10.             }
  11.         }
  12.     }
  13. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • jamesbond
  • Novice
  • Novice
  • jamesbond
  • Posts: 23

Post 3+ Months Ago

any help on this would greatly appreciated
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

You already have just about everything there... it's all about putting them in the right place :)

PHP Code: [ Select ]
<?php
 
function addFoils()
{
    global $board, $boardData;
   
    // For my rows
    for($row = 0; $row < $boardData["height"]; $row++)
    {
        // For my cols
        for($col = 0; $col < $boardData["width"]; $col++)
        {
            // The "." means to add letter to the cell
            if($board[$row][$col] == ".")
            {
                // Array from html wordlist
                $newLet = $_REQUEST["wordList"];
               
                // Convert to upper case
                $newLet = strtoupper($newLet);
               
                // Shuffles wordlist
                $board[$row][$col] = str_shuffle($newLet);
               
                // Picking the first letter as the random one
                $randLetter = substr($newLet, 0, 1);
            }
        }
    }
}
?>
  1. <?php
  2.  
  3. function addFoils()
  4. {
  5.     global $board, $boardData;
  6.    
  7.     // For my rows
  8.     for($row = 0; $row < $boardData["height"]; $row++)
  9.     {
  10.         // For my cols
  11.         for($col = 0; $col < $boardData["width"]; $col++)
  12.         {
  13.             // The "." means to add letter to the cell
  14.             if($board[$row][$col] == ".")
  15.             {
  16.                 // Array from html wordlist
  17.                 $newLet = $_REQUEST["wordList"];
  18.                
  19.                 // Convert to upper case
  20.                 $newLet = strtoupper($newLet);
  21.                
  22.                 // Shuffles wordlist
  23.                 $board[$row][$col] = str_shuffle($newLet);
  24.                
  25.                 // Picking the first letter as the random one
  26.                 $randLetter = substr($newLet, 0, 1);
  27.             }
  28.         }
  29.     }
  30. }
  31. ?>
  • jamesbond
  • Novice
  • Novice
  • jamesbond
  • Posts: 23

Post 3+ Months Ago

I figured it out. Ill post finished code when I get home

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 122 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.