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 :

[Tableaux] fonction in_array inopérante


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut [Tableaux] fonction in_array inopérante
    Bonjour,
    J'ai un petit souci avec la fonction in_array().
    Tout d'abord voici le tableau $T:
    Array ( [0] => 0 [1] => 20004 [2] => 20005 [3] => 20101 [4] => 20107 [5] => 20108 [6] => 20109 [7] => 21007 [8] => 22102 [9] => 22103 [10] => 22202 [11] => 22206 [12] => 22207 [13] => 22307 [14] => 22311 [15] => 22312 [16] => 22403 [17] => 22503 [18] => 22705 [19] => 22706 [20] => 22707 [21] => 22708 [22] => 23008 [23] => 23009 [24] => 23010 [25] => 23011 [26] => 23105 [27] => 23106 [28] => 23203 [29] => 23302 [30] => 23304 [31] => 23406 [32] => 23407 [33] => 23409 [34] => 23410 [35] => 24002 [36] => 24004 [37] => 24005 [38] => 25001 [39] => 25003 [40] => 25004 [41] => 25005 [42] => 25204 [43] => 25205 [44] => 25206 [45] => 25207 [46] => 25209 [47] => 25401 [48] => 25407 [49] => 25408 [50] => 25508 [51] => 25509 [52] => 25511 [53] => 25512 [54] => 25514 [55] => 31101 [56] => 31209 [57] => 31305 [58] => 31306 [59] => 31406 [60] => 32103 [61] => 32204 [62] => 32206 [63] => 32207 [64] => 32318 [65] => 32320 [66] => 32321 [67] => 32322 [68] => 32323 [69] => 32324 [70] => 32406 [71] => 33102 [72] => 33104 [73] => 33105 [74] => 33203 [75] => 33414 [76] => 33415 [77] => 33602 [78] => 34301 [79] => 34302 )
    Celui-ci me sert à vérifier une données issue de la base. J'effectue une requete de type select et je récupère une données $data. Puis je vérifie à chaque itération que cette donnée $data est présente dans le tableau $T.
    Pour vérifier la valeur de la fonction in_array je lance le code suivant à chaque itération:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    echo"\$data = $data<br>";
    print_r($T);
    echo"<br>";
    echo"in_array(\$data = ,\$T) = ".in_array($data = ,$T);
    echo"<br>";
    Voici le début de l'affichage (3 premières itérations):
    $data = 32323
    Array ( [0] => 0 [1] => 20004 [2] => 20005 [3] => 20101 [4] => 20107 [5] => 20108 [6] => 20109 [7] => 21007 [8] => 22102 [9] => 22103 [10] => 22202 [11] => 22206 [12] => 22207 [13] => 22307 [14] => 22311 [15] => 22312 [16] => 22403 [17] => 22503 [18] => 22705 [19] => 22706 [20] => 22707 [21] => 22708 [22] => 23008 [23] => 23009 [24] => 23010 [25] => 23011 [26] => 23105 [27] => 23106 [28] => 23203 [29] => 23302 [30] => 23304 [31] => 23406 [32] => 23407 [33] => 23409 [34] => 23410 [35] => 24002 [36] => 24004 [37] => 24005 [38] => 25001 [39] => 25003 [40] => 25004 [41] => 25005 [42] => 25204 [43] => 25205 [44] => 25206 [45] => 25207 [46] => 25209 [47] => 25401 [48] => 25407 [49] => 25408 [50] => 25508 [51] => 25509 [52] => 25511 [53] => 25512 [54] => 25514 [55] => 31101 [56] => 31209 [57] => 31305 [58] => 31306 [59] => 31406 [60] => 32103 [61] => 32204 [62] => 32206 [63] => 32207 [64] => 32318 [65] => 32320 [66] => 32321 [67] => 32322 [68] => 32323 [69] => 32324 [70] => 32406 [71] => 33102 [72] => 33104 [73] => 33105 [74] => 33203 [75] => 33414 [76] => 33415 [77] => 33602 [78] => 34301 [79] => 34302 )
    in_array($data ,$T) =
    $data = 33107
    Array ( [0] => 0 [1] => 20004 [2] => 20005 [3] => 20101 [4] => 20107 [5] => 20108 [6] => 20109 [7] => 21007 [8] => 22102 [9] => 22103 [10] => 22202 [11] => 22206 [12] => 22207 [13] => 22307 [14] => 22311 [15] => 22312 [16] => 22403 [17] => 22503 [18] => 22705 [19] => 22706 [20] => 22707 [21] => 22708 [22] => 23008 [23] => 23009 [24] => 23010 [25] => 23011 [26] => 23105 [27] => 23106 [28] => 23203 [29] => 23302 [30] => 23304 [31] => 23406 [32] => 23407 [33] => 23409 [34] => 23410 [35] => 24002 [36] => 24004 [37] => 24005 [38] => 25001 [39] => 25003 [40] => 25004 [41] => 25005 [42] => 25204 [43] => 25205 [44] => 25206 [45] => 25207 [46] => 25209 [47] => 25401 [48] => 25407 [49] => 25408 [50] => 25508 [51] => 25509 [52] => 25511 [53] => 25512 [54] => 25514 [55] => 31101 [56] => 31209 [57] => 31305 [58] => 31306 [59] => 31406 [60] => 32103 [61] => 32204 [62] => 32206 [63] => 32207 [64] => 32318 [65] => 32320 [66] => 32321 [67] => 32322 [68] => 32323 [69] => 32324 [70] => 32406 [71] => 33102 [72] => 33104 [73] => 33105 [74] => 33203 [75] => 33414 [76] => 33415 [77] => 33602 [78] => 34301 [79] => 34302 )
    in_array($data ,$T) =
    $data = 33103
    Array ( [0] => 0 [1] => 20004 [2] => 20005 [3] => 20101 [4] => 20107 [5] => 20108 [6] => 20109 [7] => 21007 [8] => 22102 [9] => 22103 [10] => 22202 [11] => 22206 [12] => 22207 [13] => 22307 [14] => 22311 [15] => 22312 [16] => 22403 [17] => 22503 [18] => 22705 [19] => 22706 [20] => 22707 [21] => 22708 [22] => 23008 [23] => 23009 [24] => 23010 [25] => 23011 [26] => 23105 [27] => 23106 [28] => 23203 [29] => 23302 [30] => 23304 [31] => 23406 [32] => 23407 [33] => 23409 [34] => 23410 [35] => 24002 [36] => 24004 [37] => 24005 [38] => 25001 [39] => 25003 [40] => 25004 [41] => 25005 [42] => 25204 [43] => 25205 [44] => 25206 [45] => 25207 [46] => 25209 [47] => 25401 [48] => 25407 [49] => 25408 [50] => 25508 [51] => 25509 [52] => 25511 [53] => 25512 [54] => 25514 [55] => 31101 [56] => 31209 [57] => 31305 [58] => 31306 [59] => 31406 [60] => 32103 [61] => 32204 [62] => 32206 [63] => 32207 [64] => 32318 [65] => 32320 [66] => 32321 [67] => 32322 [68] => 32323 [69] => 32324 [70] => 32406 [71] => 33102 [72] => 33104 [73] => 33105 [74] => 33203 [75] => 33414 [76] => 33415 [77] => 33602 [78] => 34301 [79] => 34302 )
    Comme vous pouvez le constatez, la fonction in_array ne retourne aucun résultat alors que la 1ère valeur de $data est bien présente dans la liste des valeurs du tableau $T.
    Pourriez-vous me dire pourquoi cette fonction ne retourne rien?

    Merci

    PS : in_array('32323 ' ,$T) retourne comme valeur : 1

  2. #2
    Membre chevronné Avatar de papyphp
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    438
    Détails du profil
    Informations personnelles :
    Âge : 75
    Localisation : Belgique

    Informations professionnelles :
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 438
    Par défaut
    Bonjour,

    A quoi sert le signe = derrière $data?????

  3. #3
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut
    C'est juste une faute de frappe...
    Voilà c'est modifié.

  4. #4
    Expert confirmé Avatar de Mr N.
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 5 418
    Par défaut
    pourrais-tu utiliser var_dump au lieu de print_r ?

  5. #5
    Expert confirmé Avatar de Mr N.
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    5 418
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 5 418
    Par défaut
    et faire un var_dump($data) également

  6. #6
    Membre éclairé Avatar de nicoaix
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2004
    Messages
    571
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2004
    Messages : 571
    Par défaut
    le var_dump à la place du print_r donne:
    array(80) { [0]=> string(1) "0" [1]=> string(5) "20004" [2]=> string(5) "20005" [3]=> string(5) "20101" [4]=> string(5) "20107" [5]=> string(5) "20108" [6]=> string(5) "20109" [7]=> string(5) "21007" [8]=> string(5) "22102" [9]=> string(5) "22103" [10]=> string(5) "22202" [11]=> string(5) "22206" [12]=> string(5) "22207" [13]=> string(5) "22307" [14]=> string(5) "22311" [15]=> string(5) "22312" [16]=> string(5) "22403" [17]=> string(5) "22503" [18]=> string(5) "22705" [19]=> string(5) "22706" [20]=> string(5) "22707" [21]=> string(5) "22708" [22]=> string(5) "23008" [23]=> string(5) "23009" [24]=> string(5) "23010" [25]=> string(5) "23011" [26]=> string(5) "23105" [27]=> string(5) "23106" [28]=> string(5) "23203" [29]=> string(5) "23302" [30]=> string(5) "23304" [31]=> string(5) "23406" [32]=> string(5) "23407" [33]=> string(5) "23409" [34]=> string(5) "23410" [35]=> string(5) "24002" [36]=> string(5) "24004" [37]=> string(5) "24005" [38]=> string(5) "25001" [39]=> string(5) "25003" [40]=> string(5) "25004" [41]=> string(5) "25005" [42]=> string(5) "25204" [43]=> string(5) "25205" [44]=> string(5) "25206" [45]=> string(5) "25207" [46]=> string(5) "25209" [47]=> string(5) "25401" [48]=> string(5) "25407" [49]=> string(5) "25408" [50]=> string(5) "25508" [51]=> string(5) "25509" [52]=> string(5) "25511" [53]=> string(5) "25512" [54]=> string(5) "25514" [55]=> string(5) "31101" [56]=> string(5) "31209" [57]=> string(5) "31305" [58]=> string(5) "31306" [59]=> string(5) "31406" [60]=> string(5) "32103" [61]=> string(5) "32204" [62]=> string(5) "32206" [63]=> string(5) "32207" [64]=> string(5) "32318" [65]=> string(5) "32320" [66]=> string(5) "32321" [67]=> string(5) "32322" [68]=> string(5) "32323" [69]=> string(5) "32324" [70]=> string(5) "32406" [71]=> string(5) "33102" [72]=> string(5) "33104" [73]=> string(5) "33105" [74]=> string(5) "33203" [75]=> string(5) "33414" [76]=> string(5) "33415" [77]=> string(5) "33602" [78]=> string(5) "34301" [79]=> string(5) "34302" }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Fonction in_array() inopérante
    Par trifly dans le forum Langage
    Réponses: 10
    Dernier message: 19/10/2011, 14h22
  2. [Tableaux] Fonction in_array pas claire
    Par Hightuxdotnet dans le forum Langage
    Réponses: 9
    Dernier message: 13/01/2009, 14h42
  3. [Tableaux] Pb avec fonction in_array
    Par yveslens dans le forum Langage
    Réponses: 4
    Dernier message: 27/03/2007, 13h34
  4. Réponses: 9
    Dernier message: 17/02/2006, 11h04
  5. [Tableaux] fonction retournant le 1er charactere
    Par Pepito dans le forum Langage
    Réponses: 4
    Dernier message: 22/11/2005, 14h59

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