Okay I'm trying the make a script that creates a 15 random but unique numbers between 11 and 99 and puts them in an array, once the script has created a random number it will get the korean words for those numbers and put them in another array so I'd end up with something like
num[1] = 36
ans[1] = sorunyosot
num[2] = 12
ans[2] = yoldool
hana and yoldool being the korean for 36 and 12 respectfully.
What the script actually does is create 15 random numbers and their korean, but they're not always unique. I'm currently getting this error:
Notice: Undefined offset: 0 in /home/vhosts/quizsamples.atbhost.com/public_html/num_array.php on line 21
which refers to the while statement. So what I'm thinking is that I'm incorrectly pointing to the variables or something like that. Here's the code that I have
<?php
$arr = array("units" => array(1 => "hana", "dool", "set", "net", "tasot", "yosot", "ilgop",
"yodol", "ahop"), "tens" => array(10 => "yol", 20 => "samul", 30 => "sorun", 40 => "mahun", 50 =>
"chiun", 60 => "yesun", 70 => "irrun", 80 => "yodun", 90 => "ahun"), "hundreds" => array(100 =>
"pek"));
$ans = array(0 => 0);
$a;
$b;
$c;
for($a = 1; $a < 16; $a = $a + 1) {
$var1 = rand(1,9)*10;
$var2 = rand(1,9);
$num = array($a => $var1 + $var2);
$ans = array($a => $arr["tens"][$var1].$arr["units"][$var2]);
for($b = 0; $b < $a - 1; $b = $b + 1) {
while($num[$a] == $num[$b]) {
$var1 = rand(1,9)*10;
$var2 = rand(1,9);
$num = array($a => $var1 + $var2);
}
}
echo $num[$a].'<br />'.$ans[$a].'<br />';
}
?>
Any ideas on how to correct it?