0
Find, in any vector of integer values, a certain element of this, given its value in php:
<?php
$vet=array(3, 9, 7, 5, 6);
$chave = 9; // valor que se deseja localizar
$nao_localizado = true;
$candidato = 0; // indice do candidato no vetor
while ( $nao_localizado && $candidato < $vet){
if ( $vet[ $candidato ] == $chave ){
$nao_localizado = false; // localizado o valor
}else{
$candidato++; // avanca para o proximo candidato/editing-help
}
if ( $nao_localizado ){
echo( "Nao foi localizado o valor " . $chave );
}
else{
echo( "O valor " . $chave .
" foi localizado na posicao " . $candidato );
}
}
?>
You could further detail your question. In order to make it clear what you want to know. If you can add an example and the codes you are using.
– Allan Andrade
This code is working more or less, the key variable in the code is 9 as it has in the vector 9 it is to say the value and say the position only that at the time of showing this it is showing 2 messages with which it does not find and soon after it shows the right that I find and says the position.
– Rebeca Queiroz
And if I take out of the key variable the value 9 and put another number that does not have in the vector it appears the right answer, only if repeating and error soon after the answer
– Rebeca Queiroz
<?php $vet=array(3, 9, 7, 5, 6); $key = 9; // value you want to locate $nao_located = true; $candidate = 0; // candidate input in vector while ( $nao_located && $candidate < $vet){ if ( $vet[ $candidate ] == $key ){ $nao_localized = false; // located the value }Else{ $candidate++; } if ( $nao_localized ){ echo( "No value found " . $key ); } Else{ echo( "The value " . $key . " was located in position " . $candidate ); } } 
 a; ?>
– Rebeca Queiroz
Copy the code I made below and run on your server and tell me if you understand ok?
– Allan Andrade