I’ll Post, HELLO, WORLD
Expecting
HELLO,6
H
E
L
L
O
,
WORLD5
W
O
R
L
D
Instead I get
HELLO,6
H
E
L
L
O
,
WORLD5
There 2nd word will not spell?
$name = $_POST['engname'];
$convert = array_combine($letters, $jap);
function get_num_of_names($name) {
$name = explode(" ", $name);
$name_mainlen = count($name);
for($i=0; $i <= $name_mainlen + 1; $i++) {
echo $name[$i];
$name[$i] = str_split($name[$i]);
$namelen = count($name[$i]);
echo $namelen . '<br/>';
function spellname($x, $namelen) {
for($i=0; $i <= $namelen; $i++) {
echo $x[$i] . '<br/>';
}
}
spellname($name[$i], $namelen);
}
}
get_num_of_names($name);
You’re defining a function in a loop. Your script should implode with a
Function 'spellname' already definederror, if you’d activate error reporting.A function is defined when it is encountered. If you place it in a loop, it will be defined on each iteration. Since you can’t define two functions with the same name, your script aborts with a fatal error.
Apart from that, there are much easier ways to do what you want to do:
Or, as a one-liner:
Or, even shorter with different approach (regards to @Long Ears):