IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

in_array ne trouve pas la chaine


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut in_array ne trouve pas la chaine
    Je la fonction in_array me renvoit rein comment faire pour faire fonctionner cela?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    require_once  $_SERVER['DOCUMENT_ROOT'].'Dashboard/core/includes.php';
     $conditionregion = array( "fields" => "DISTINCT (pays)","order"=>"pays ASC",
                        'conditions'=> ' region= "worldwide"' );
      $regionselected = $region->find($conditionregion);
       $conditionregionselected = array();
      foreach ($regionselected as $key => $value) {
     
      $conditionregionselected [] = $value["pays"];   
      }
     
     
     
      print_r($conditionregionselected);
      if ( in_array( "Canon Marketing Japan" , $conditionregionselected))echo "coucou";
      else echo "aurevoir";
    contenu du tableau

    [0] => Canon Europe [1] => Canon Marketing Japan [2] => Canon Singapore RSHQ [3] => Canon USA [4] => HQ [5] => Océ Australia

  2. #2
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Par défaut
    in_array est sensible à la casse pour les comparaisons de chaine. Il faut également faire attention aux espaces (genre "chaine ", " chaine " et " chaine" sont trois chaines différentes)
    Vérifie ces deux points.
    Tu peux aussi faire la comparaison manuellement avec une bonne vieille boucle
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut
    J'ai la meme casse et pas d'espace :s

  4. #4
    Membre Expert
    Avatar de Dendrite
    Femme Profil pro
    Développeuse informatique
    Inscrit en
    Juin 2008
    Messages
    2 129
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 59
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeuse informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Juin 2008
    Messages : 2 129
    Billets dans le blog
    8
    Par défaut
    Trouvé dans la doc de la fonction cette remarque, et comme je vois que dans ton tableau tu as un problème d'accent, je me dis que ça a peut-être à voir avec l'encodage.

    This function has Problem with UTF-8. To solve this Problem use:

    in_array( mb_strtolower($tag, "UTF-8"), $arr)
    PDO, une soupe et au lit !
    Partir de la fin est un bon moyen de retrouver son chemin. Bibi - 2020

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut
    j'ai essaye maleurement ca ne marche pas j'ai essaye le code suivant :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    require_once  $_SERVER['DOCUMENT_ROOT'].'Dashboard/core/includes.php';
     $conditionregion = array( "fields" => "DISTINCT (pays)","order"=>"pays ASC",
                        'conditions'=> ' region= "worldwide"',"connexion" => "merlin2" );
      $regionselected = $region->findpdo($conditionregion);
     
     // print_r($regionselected);
     
      echo  compare($regionselected,"Canon Marketing Japan","pays");
     
     
     
     
     function compare($tableau,$valeur,$keys){
     
          foreach ($tableau as $key => $value) {
          echo $value[$keys]." ";echo"</br>";echo $valeur ;
          echo strcmp($value[$keys],$valeur) ;echo"</br>";
          echo"</br>";
          }
          return 0;
      }
    qui me retourne des reponces etrange :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    Canon Europe
    Canon Marketing Japan-1
     
    Canon Marketing Japan
    Canon Marketing Japan1
     
    Canon Singapore RSHQ
    Canon Marketing Japan1
     
    Canon USA
    Canon Marketing Japan1
     
    HQ
    Canon Marketing Japan1
     
    Océ Australia
    Canon Marketing Japan1
     
    Océ Austria
    Canon Marketing Japan1
     
    Océ Belgium
    Canon Marketing Japan1
     
    Océ Brazil
    Canon Marketing Japan1
     
    Océ Brazil;Océ Direct Export
    Canon Marketing Japan1
     
    Océ Czech Republic
    Canon Marketing Japan1
     
    Océ Direct Export
    Canon Marketing Japan1
     
    Océ Far East
    Canon Marketing Japan1
     
    Océ France
    Canon Marketing Japan1
     
    Océ Germany
    Canon Marketing Japan1
     
    Océ Great Britain
    Canon Marketing Japan1
     
    Océ Hong Kong
    Canon Marketing Japan1
     
    Océ Hungary
    Canon Marketing Japan1
     
    Océ Ireland
    Canon Marketing Japan1
     
    Océ Italy
    Canon Marketing Japan1
     
    Océ Japan
    Canon Marketing Japan1
     
    Océ Malaysia
    Canon Marketing Japan1
     
    Océ Nordic
    Canon Marketing Japan1

  6. #6
    Expert confirmé
    Avatar de N1bus
    Homme Profil pro
    Dev. Web & OpenERP
    Inscrit en
    Janvier 2003
    Messages
    2 827
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Dev. Web & OpenERP
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 827
    Par défaut
    Bonjour,

    J'ai testé avec ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
    $conditionregionselected = array('Canon Europe', 
             'Canon Marketing Japan', 
             'Canon Singapore RSHQ', 
             'Canon USA', 
             'HQ', 
             'Océ Australia');
    print_r($conditionregionselected);
      if ( in_array( "Canon Marketing Japan" , $conditionregionselected))echo "coucou";
      else echo "aurevoir";
     
    ?>
    Et ça me retourne "coucou"
    Ça marche.

Discussions similaires

  1. [XL-2002] Rechercher dans une chaine si 1 car ne se trouve pas dedans.
    Par cmako dans le forum Excel
    Réponses: 4
    Dernier message: 26/11/2009, 13h39
  2. [jonas]eclipse ne trouve pas le plugin
    Par Stessy dans le forum Eclipse Java
    Réponses: 5
    Dernier message: 17/07/2007, 11h43
  3. je ne trouve pas la bonne syntaxe
    Par poelvo dans le forum Langage SQL
    Réponses: 2
    Dernier message: 14/08/2003, 01h30
  4. [TP]trouve pas le graph.tpu
    Par kaygee dans le forum Turbo Pascal
    Réponses: 12
    Dernier message: 13/06/2003, 12h49
  5. [Kylix] [cgi] ne trouve pas libsqlmy.so.1 !
    Par Nepomiachty Olivier dans le forum EDI
    Réponses: 3
    Dernier message: 04/07/2002, 15h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo