Dear experienced developers and apprentices of the art of coding.
I think it's common for some system to have to check the next item for a array
. For example in this case I'm checking if the next one is the same as the previous item:
$item_anterior = "";
$array = [0,1,2,3,4,5,6,7,8,9,10];
$ainda_nao_foi = true;
for($i=0;$i<$array.lenght();$i++){
if($ainda_nao_foi){
echo "<p>O Site do Stack overflow é demais! .$array[$i].</p>";
$item_anterior = $array[$i];
$ainda_nao_foi = false;
}
//próximo
$j = $i + 1;
if($item_anterior != array[$j]){
$ainda_nao_foi = true;
}
}
Even though I use the isset () function to check if it's set, this would not help, because sometimes my array may return empty.
The problem is that in this if
:
if($item_anterior != array[$j]){
$ainda_nao_foi = true;
}
The PHP
generates a warning
warning that the index is not set. Is there a function that checks to see if it has this index in array
? to not break the error?