Suppose you have the following code:
for($i=1; $i<=$_SESSION["participants"][0]; $i++){
if($name[$i] == "name $i"){
echo "You forgot to change the word *name $i* with the name of person $i.<br>";
} elseif($name[$i] == NULL){
echo "You forgot to enter person $i 's name!<br>";
} else{
echo "The process of entering person $i 's name was successful!<br>";
} }
My problem is with the $i. When i set this to 1, $name[$i] becomes $name[1] which shows the second word in the array. Why is that a problem? Well, because I've also used $i for indicating the order of "person", e.g person 1, person 2, person 3 and so on, by using $i++.
In other words, if $i were to be 1 the if-statement inside the loop would basically check whether the second word in the array, namely "name 2" matches with the value "name 1", instead of checking the first word ("name 1") like it's supposed to, which causes the third condition to always be true when it's not.
I've attempted to make a second $i (except it was called $p), which would start at 0 while the OG $i would start at 1. But to no avail unfortunately.
Is there a way to fix this?
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire