grumpy
08-07-2008, 02:30 PM
Hey,
Here's the problem...
calling the function:
$name_out = ($fname_out . $lname_out);
$name_out_array = preg_split('//', $name_out, -1, PREG_SPLIT_NO_EMPTY);
$name_out_array = $letter;
for ($i=0; $i <= sizeof($letter); $i++)
{
NumTable ($letter, $i);
}
$name_num = array_sum(array ($letter));
The $fname and $lname variables are Firstname and Lastname of a person. The code combines them both, then splits both names into individual letters and then calls the function to replace all the letters with corresponding numbers.
Here's the function:
function NumTable ($letter, $i)
{
if (($letter[$i] == "a") || ($letter[$i] == "j") || ($letter[$i] == "s"))
{
$letter[$i] = 1;
}
else if (($letter[$i] == "b") || ($letter[$i] == "k") || ($letter[$i] == "t"))
{
$letter[$i] = 2;
}
else if (($letter[$i] == "c") || ($letter[$i] == "l") || ($letter[$i] == "u"))
{
$letter[$i] = 3;
}
else if (($letter[$i] == "d") || ($letter[$i] == "m") || ($letter[$i] == "v"))
{
$letter[$i] = 4;
}
else if (($letter[$i] == "e") || ($letter[$i] == "n") || ($letter[$i] == "w"))
{
$letter[$i] = 5;
}
else if (($letter[$i] == "f") || ($letter[$i] == "o") || ($letter[$i] == "x"))
{
$letter[$i] = 6;
}
else if (($letter[$i] == "g") || ($letter[$i] == "p") || ($letter[$i] == "y"))
{
$letter[$i] = 7;
}
else if (($letter[$i] == "h") || ($letter[$i] == "q") || ($letter[$i] == "z"))
{
$letter[$i] = 8;
}
else if (($letter[$i] == "i") || ($letter[$i] == "r"))
{
$letter[$i] = 9;
}
else if ($letter[$i] == " ")
{
$letter[$i] = 0;
}
}
Instead of some numbers 1-9 the output of the function is constantly empty (0) which is an error. What would be the reason?
Would it be better to use a foreach then, instead of the for loop and the $i variable, and if so, how would you do it?
Here's the problem...
calling the function:
$name_out = ($fname_out . $lname_out);
$name_out_array = preg_split('//', $name_out, -1, PREG_SPLIT_NO_EMPTY);
$name_out_array = $letter;
for ($i=0; $i <= sizeof($letter); $i++)
{
NumTable ($letter, $i);
}
$name_num = array_sum(array ($letter));
The $fname and $lname variables are Firstname and Lastname of a person. The code combines them both, then splits both names into individual letters and then calls the function to replace all the letters with corresponding numbers.
Here's the function:
function NumTable ($letter, $i)
{
if (($letter[$i] == "a") || ($letter[$i] == "j") || ($letter[$i] == "s"))
{
$letter[$i] = 1;
}
else if (($letter[$i] == "b") || ($letter[$i] == "k") || ($letter[$i] == "t"))
{
$letter[$i] = 2;
}
else if (($letter[$i] == "c") || ($letter[$i] == "l") || ($letter[$i] == "u"))
{
$letter[$i] = 3;
}
else if (($letter[$i] == "d") || ($letter[$i] == "m") || ($letter[$i] == "v"))
{
$letter[$i] = 4;
}
else if (($letter[$i] == "e") || ($letter[$i] == "n") || ($letter[$i] == "w"))
{
$letter[$i] = 5;
}
else if (($letter[$i] == "f") || ($letter[$i] == "o") || ($letter[$i] == "x"))
{
$letter[$i] = 6;
}
else if (($letter[$i] == "g") || ($letter[$i] == "p") || ($letter[$i] == "y"))
{
$letter[$i] = 7;
}
else if (($letter[$i] == "h") || ($letter[$i] == "q") || ($letter[$i] == "z"))
{
$letter[$i] = 8;
}
else if (($letter[$i] == "i") || ($letter[$i] == "r"))
{
$letter[$i] = 9;
}
else if ($letter[$i] == " ")
{
$letter[$i] = 0;
}
}
Instead of some numbers 1-9 the output of the function is constantly empty (0) which is an error. What would be the reason?
Would it be better to use a foreach then, instead of the for loop and the $i variable, and if so, how would you do it?