Comparer une chaine de caractère dans un tableau
Résolu
europe21
Messages postés
63
Date d'inscription
Statut
Membre
Dernière intervention
-
europe21 Messages postés 63 Date d'inscription Statut Membre Dernière intervention - 14 août 2020 à 19:21
europe21 Messages postés 63 Date d'inscription Statut Membre Dernière intervention - 14 août 2020 à 19:21
A voir également:
- Comparer une chaine de caractère dans un tableau
- Caractère ascii - Guide
- Tableau word - Guide
- Trier un tableau excel - Guide
- Caractère spéciaux - Guide
- Caractere speciaux - Guide
3 réponses
Bonjour
Tu parles de tableau... Donc d'array ?
Si c'est ça... Il existe des fonctions php pour ça... In_array par exemple
Tu parles de tableau... Donc d'array ?
Si c'est ça... Il existe des fonctions php pour ça... In_array par exemple
Oui c'est un array.
J'ai fait cela:
Mais j'ai ce message d'erreur:
Warning: in_array() expects parameter 2 to be array, string given
J'ai fait cela:
$repo = $this->getDoctrine()->getRepository(CategoryAdherent::class);;
$cat = $repo->findAll();
foreach($cat as $listecat)
{
$liste= $listecat->getTitle();
if (in_array("u 19", $liste)) {
var_dump('c est bon');
}
}
Mais j'ai ce message d'erreur:
Warning: in_array() expects parameter 2 to be array, string given
string(4) "u 19" string(4) "u 20" string(4) "u 18" string(1) "a" string(1) "b" string(3) "u15" string(9) "dirigeant"
Par contre j'obtiens un resultat si je code comme cela:
foreach($cat as $listecat)
{
$liste= $listecat->getTitle();
if (in_array($adherent->getSubCategory(), array($liste))) {
var_dump('c est bon');
}else
var_dump('c est pas bon');
}
J'obtiens cela:
string(13) "c est pas bon" string(13) "c est pas bon" string(9) "c est bon" string(13) "c est pas bon" string(13) "c est pas bon" string(13) "c est pas bon" string(13) "c est pas bon"