I'm trying to create a dictionary website and I came into some issues. I am printing the first value of array to the website. I'm trying to check if the input that is submitted into textbox is the same as translation of the word that is displayed at my website. If yes, then I need to remove that element from an array so that the first value of array now would be a second value from original array and so on, until the array is empty. After that, I would have an array with words that user didn't knew how to translate.
So my question is, how do I remove an element from array so that indexes wouldn't mess up? Or is there a better way to solve my problem?
<?php
$servername = "localhost";
$username = "stud";
$password = "stud";
$dbname = "zodynas-eng";
//Connection
$conn = new mysqli($servername, $username, $password, $dbname);
//Check
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM politephrases";
$result = $conn->query($sql);
//Create an empty array
$array = array();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$array[] = $row;
}
}
echo "<br>";
//shuffle($array);
echo "<h2>Word: </h2>";
$i = 0;
echo $array[$i]['word'];
echo '<form name = "tr" method = "post" action = "polite-phrases-eng.php">
<br>
<input type = "text" value = "" name = "translation">
<input type = "submit" name = "submit1" value = "Vykdyti">
</form>';
if(!empty($_POST)){
if($array[$i]['transl'] == $_POST) {
echo "<br> Good job";
//Remove an element from array
}
else {
//Save the element from input to wrongGuessArray
}
}
else {
echo "<br><p>Translation</p>";
}
$conn->close();
?>