I have an array with letters of the alphabet and the idea is that through a form where a letter and number are typed, the chosen letter is moved the number of times it is inserted.
This is the php code:
<?php
$letras = array
(
0 => "a",
1 => "b",
2 => "c",
3 => "d",
4 => "e",
5 => "f",
6 => "g",
7 => "h",
8 => "i",
9 => "j",
10 => "k",
11 => "l",
12 => "m",
13 => "n",
14 => "ñ",
15 => "o",
16 => "p",
17 => "q",
18 => "r",
19 => "s",
20 => "t",
21 => "u",
22 => "v",
23 => "w",
24 => "x",
25 => "y",
26 => "z"
);
$letra = $_POST['letra'];
$numero = $_POST['numero'];
//echo $letra;
//echo $numero;
$var=array_search($letra,$letras);
print_r ($var);
foreach ($letras as $clave => $valor)
{
if ($letra == $valor)
{
echo "encontrado";
}
}
echo "<br>";
echo "<br>";
print_r ($letras);
?>
The html is simply to insert the letter and number.
It works like this: Enter letter: a Enter number: 3 this results in: d, since a has moved 3 times.
As it is now when I enter a letter it locates the position but I don't know how to do it so that when I enter the number, it increases the position and shows me the new position. Thanks.
1 Answers