post #1 of 4
Thread Starter 
Backstory: Long story short, this script is for a christmas secret santa drawing. 1 person will have to draw 3 names. I have 9 people that will be drawing. What i got so far is that it grabs 3 random names from the pool and assigns the names to each person. The thing i need help on is I only want each name to be drawn 3 times. Help?
Code:

$sia = "Sia";
$stacie = "Stacie";
$apollo = "Apollo";
$kim = "Kim";
$pheng = "Pheng";
$pahoua = "Pahoua";
$mom = "Mom";
$dad = "Dad";
$kou = "Kou";

$drawer = array($sia, $stacie, $apollo, $kim, $pheng, $pahoua, $mom, $dad, $kou);
$names = array($sia, $stacie, $apollo, $kim, $pheng, $pahoua, $mom, $dad, $kou);

foreach ($drawer as $picker)
{
        echo $picker . ": <br/>";
        
        shuffle($names); //shuffles the names
        
        $shuffledname = array_rand($names, 3); //Only shows 3 random names that were shuffled
        
        $name1 = $names[$shuffledname[0]];
        $name2 = $names[$shuffledname[1]];
        $name3 = $names[$shuffledname[2]];
        
        echo $name1 . "<br />";
        echo $name2 . "<br />";
        echo $name3 . "<br /><br />";
}


This is the outcome:

Sia:
Sia
Kou
Dad

Stacie:
Apollo
Pahoua
Dad

Apollo:
Dad
Kou
Apollo

Kim:
Kim
Pahoua
Stacie

Pheng:
Kim
Sia
Pheng

Pahoua:
Pheng
Pahoua
Dad

Mom:
Stacie
Mom
Apollo

Dad:
Sia
Stacie
Kou

Kou:
Stacie
Apollo
Kou
Mini Me
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7 3770k ASRock Z77E-ITX LGA1155 Z77 mini ITX EVGA GTX 670 4gb 16gb Corsair Vengeance 
Hard DriveCoolingOSMonitor
256gb Crucial m4 Antec 620 Windows 7 Ultimate 64bit Dell U231HM 23.5" IPS 
KeyboardPowerCaseMouse
Microsoft digital media 3000 Corsair cx500m Fractal Design Node304 Cooler Master xornet 
Mouse PadAudio
custom Sony MDR-V6 
  hide details  
Reply
Mini Me
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7 3770k ASRock Z77E-ITX LGA1155 Z77 mini ITX EVGA GTX 670 4gb 16gb Corsair Vengeance 
Hard DriveCoolingOSMonitor
256gb Crucial m4 Antec 620 Windows 7 Ultimate 64bit Dell U231HM 23.5" IPS 
KeyboardPowerCaseMouse
Microsoft digital media 3000 Corsair cx500m Fractal Design Node304 Cooler Master xornet 
Mouse PadAudio
custom Sony MDR-V6 
  hide details  
Reply
post #2 of 4
Quick idea.

Make the names array multi-dimensional. So array of ["name", integer]. Start integer at 0. Each time name is picked. Update integer. If integer is >= 3. Redraw.

Edit:
: Hmm, not sure if that would work with the way you are doing the code right now. Just looked at it a little closer. You would have to have an inner loop of 3 for each name for it to work like I was thinking. Your way is less code, which is usually a good thing, but you may not be able to accomplish what you want doing it that way.
Edited by glakr - 10/24/12 at 10:16pm
White TITAN
(16 items)
 
   
CPUMotherboardGraphicsRAM
intel core i7-3770k Asus Z77 Sabertooth EVGA Titan SC Corsair Dominator Platinum 16GB (2x8GB) 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro  WD Black Crucial M4 LG Blueray 
CoolingOSMonitorPower
Swiftech H220 Windows 7 64bit Dell 2311h Ultrasharp x 2 Corsair AX850 
CaseMouseMouse PadAudio
Fractal Design Define R4 White (w/ Window) Logitech G700 Razer Control Edition Sound Blaster ZxR 
CPUMotherboardGraphicsRAM
Intel 980x Asus Rampage iii Extreme EVGA GTX580 SLI Patriot Viper Xtreme 12GB DDR3 2000 (PC3 16000) 
Hard DriveHard DriveHard DriveOptical Drive
120GB Corsair Force Series 3 SSD WD Caviar Black 640GB Crucial M4 128GB SSD LG Black Blu-ray Drive SATA Model UH12LS28 
CoolingCoolingCoolingCooling
XSPC RX360 and RX120 Rads Watercool HeatKiller 3.0 Limited Edition Black ... XSPC Dual Bay Res with Swiftech MCP655 Pump Silver Shining Bitspower Compression Fittings 
CoolingCoolingCoolingCooling
PrimoFlex Pro LRT Black Tubing -1/2in. ID X 3/4in. 3x Gentle Typhoon 120mm Fan 1850RPM (AP-15)  1x Noiseblocker NB-BlackSilentPro PL-2 120mm Ul... Koolance VID-NX580 Full Cover GPU Waterblock x2 
OSMonitorKeyboardPower
Windows 7 Home Premium x64 Dell U2311 Ultrasharp x2 Max Keyboard Nighthawk X8 Semi-Custom - Mechani... Antec High Current Gamer 900W 
CaseMouseMouse PadAudio
Xigmatek Elysium Black Logitech G700 Razer Goliathus Creative Sound Blaster Recon3D Fatal1ty Pro 
  hide details  
Reply
White TITAN
(16 items)
 
   
CPUMotherboardGraphicsRAM
intel core i7-3770k Asus Z77 Sabertooth EVGA Titan SC Corsair Dominator Platinum 16GB (2x8GB) 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 Pro  WD Black Crucial M4 LG Blueray 
CoolingOSMonitorPower
Swiftech H220 Windows 7 64bit Dell 2311h Ultrasharp x 2 Corsair AX850 
CaseMouseMouse PadAudio
Fractal Design Define R4 White (w/ Window) Logitech G700 Razer Control Edition Sound Blaster ZxR 
CPUMotherboardGraphicsRAM
Intel 980x Asus Rampage iii Extreme EVGA GTX580 SLI Patriot Viper Xtreme 12GB DDR3 2000 (PC3 16000) 
Hard DriveHard DriveHard DriveOptical Drive
120GB Corsair Force Series 3 SSD WD Caviar Black 640GB Crucial M4 128GB SSD LG Black Blu-ray Drive SATA Model UH12LS28 
CoolingCoolingCoolingCooling
XSPC RX360 and RX120 Rads Watercool HeatKiller 3.0 Limited Edition Black ... XSPC Dual Bay Res with Swiftech MCP655 Pump Silver Shining Bitspower Compression Fittings 
CoolingCoolingCoolingCooling
PrimoFlex Pro LRT Black Tubing -1/2in. ID X 3/4in. 3x Gentle Typhoon 120mm Fan 1850RPM (AP-15)  1x Noiseblocker NB-BlackSilentPro PL-2 120mm Ul... Koolance VID-NX580 Full Cover GPU Waterblock x2 
OSMonitorKeyboardPower
Windows 7 Home Premium x64 Dell U2311 Ultrasharp x2 Max Keyboard Nighthawk X8 Semi-Custom - Mechani... Antec High Current Gamer 900W 
CaseMouseMouse PadAudio
Xigmatek Elysium Black Logitech G700 Razer Goliathus Creative Sound Blaster Recon3D Fatal1ty Pro 
  hide details  
Reply
post #3 of 4
Thread Starter 
^^ Thanks for helping. I had to go a different route. But i got it to work. A little more code, but at least it works. Thanks. BTW here's what i did.
Code:
<?php
$sia = "Sia";
$stacie = "Stacie";
$apollo = "Apollo";
$kim = "Kim";
$pheng = "Pheng";
$pahoua = "Pahoua";
$mom = "Mom";
$dad = "Dad";
$victor = "Victor";

$drawer = array($sia, $stacie, $apollo, $kim, $pheng, $pahoua, $mom, $dad, $victor);
$name1 = array($sia, $stacie, $apollo, $kim, $pheng, $pahoua, $mom, $dad, $victor);
$name2 = array($sia, $stacie, $apollo, $kim, $pheng, $pahoua, $mom, $dad, $victor);
$name3 = array($sia, $stacie, $apollo, $kim, $pheng, $pahoua, $mom, $dad, $victor);

foreach ($drawer as $picker)
{
        while ($name1[0] == $picker)
                {
                        shuffle($name1);
                }
                
//Name 2 starts here
                
        while (($name2[0] == $picker) OR ($name2[0] == $name1[0]))
                {
                        shuffle($name2);
                }
                
//Name 3 starts here

        while (($name3[0] == $picker) OR ($name3[0] == $name1[0]) OR ($name3[0] == $name2[0]))
                {
                        shuffle($name3);
                }

                echo $picker . ": " . $name1[0] . ", " . $name2[0] . ", " . $name3[0] . "<br/>";

// Emailing starts here

        $from = "whatever@whatever.com";
        $message = "Welcome to the Blank Secret Santa gift exchange.\n The automatic name picker has drawn names for you.\n Don't forget that the limit for each person is $50. This year we will have a total of 3 people to buy a gift for.\n Here is the list of people that you would have to buy gifts for: \n\n" . $picker . ": " . $name1[0] . ", " . $name2[0] . ", " . $name3[0];
        $headers = "From:" . $from;

        if ($picker == "Sia")
        {
                mail('whateveremail@whateveremail.com', 'Christmas Secret Santa Gift  Exchange', $message, $headers);
        }

        $name1 = array_slice($name1,1);
        $name2 = array_slice($name2,1);
        $name3 = array_slice($name3,1);
}

ini_set('max_execution_time', 20); 


Mini Me
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7 3770k ASRock Z77E-ITX LGA1155 Z77 mini ITX EVGA GTX 670 4gb 16gb Corsair Vengeance 
Hard DriveCoolingOSMonitor
256gb Crucial m4 Antec 620 Windows 7 Ultimate 64bit Dell U231HM 23.5" IPS 
KeyboardPowerCaseMouse
Microsoft digital media 3000 Corsair cx500m Fractal Design Node304 Cooler Master xornet 
Mouse PadAudio
custom Sony MDR-V6 
  hide details  
Reply
Mini Me
(15 items)
 
  
CPUMotherboardGraphicsRAM
i7 3770k ASRock Z77E-ITX LGA1155 Z77 mini ITX EVGA GTX 670 4gb 16gb Corsair Vengeance 
Hard DriveCoolingOSMonitor
256gb Crucial m4 Antec 620 Windows 7 Ultimate 64bit Dell U231HM 23.5" IPS 
KeyboardPowerCaseMouse
Microsoft digital media 3000 Corsair cx500m Fractal Design Node304 Cooler Master xornet 
Mouse PadAudio
custom Sony MDR-V6 
  hide details  
Reply
post #4 of 4