Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
How to match letters and check that value is present inside array or not using PHP

I need one help. I need to check that string is present inside array or not and also it should search letter wise using PHP. I am explaining my code below.

$resultArr=array("9937229853","9937229856","9937229875");
$searchValue="+919937229853";

Here I need to check that some of the value from $searchValue is present inside in array or not. I am doing like below but its not giving me the proper result.

$searchValue="+919937229853";
$resultArr=array("9937229853","9937229856","9937229875");
if(!in_array($searchValue, $resultArr))
{
 $flag=1;
}else{
  $flag=0;
}
echo $flag;

As per my requirement here result should print 1 because some value from $searchValue also present in that array but the echo result is coming 0.Please help me.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

you can try code like below.

if(!in_array(substr($searchValue,-10), $resultArr))
over 4 years ago · Santiago Trujillo Relatório

0

The function below will return true if either

  • your $searchValue is in the array (in_array), or
  • if any item of the array is a substring of $searchValue
    in other words: If part of $searchValue is in the array.

This is the code and how you call it:

function search($needle, $haystack) {
    // is $needle contained in the array as it is?
    if (in_array($needle, $haystack))
        return true;

    // Is any part of $needle part of the array?
    foreach ($haystack as $value) {
        if (strpos($needle, $value) !== FALSE)
            return true;
    }

    return false;
}

$resultArr = array("9937229853", "9937229856", "9937229875");
$searchValue = "+919937229853";

$result = search($searchValue, $resultArr);
var_dump($result);
over 4 years ago · Santiago Trujillo Relatório

0

$searchValue="+919937229853";
$searchValue = str_replace("+91","",$searchValue);
$resultArr=array("9937229853","9937229856","9937229875");
if(in_array($searchValue, $resultArr))
{
 $flag=1;
}else{
  $flag=0;
}
echo $flag;

User str_replace function replace first three charater from string

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda