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 :

Triage des valeurs tableau [PHP 5.3]


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 118
    Points : 54
    Points
    54
    Par défaut Triage des valeurs tableau
    Bonjour à tous

    voici un problème que j'ai trouver ici:
    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
     
     <?php
     
    $tab = str_word_count($chaine, 2);
    $occ = array();
    foreach ($tab as $word)
    {
       if (!isset($occ[$word]))
          $occ[$word] = 0;
          $occ[$word]++;
    }
     ?>
    <h2><span>Statistique d'occurences</span></h2>
     
                        <div class="module-body">
                        <table id="myTable" class="tablesorter">
                            	<thead>
                                    <tr>
     
                                        <th style="width:20%">Mots</th>
                                        <th style="width:21%">Nombre d'occurence</th>
                                        <th style="width:15%">Triage Croisance</th>
                                    </tr>
                                </thead>
     
                                <tbody>
    <?php 
    foreach($occ as $cle=>$valeur) 
        { 
              echo "<tr><td><a href'#'>$cle</a></td><td>$valeur</td><td></td></tr>";
    	}
    ?>

    Je veux trier les résultats des occurrences des mots dans l’ordre croissance et décroissance.

    Merci d'avance.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Et qu'est ce qui te bloque ?
    Ce n'est pas ce qui manque des fonctions de tri de tableau en PHP.

  3. #3
    Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 118
    Points : 54
    Points
    54
    Par défaut
    J'ai utilisé ce code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $table[]=array_multisort($cle, SORT_ASC, SORT_STRING, $valeur,SORT_NUMERIC, SORT_DESC);// tri croissance des string & tri décroissance numérique
    echo "<tr><td><a href'#'>$table[$cle]</a></td><td>$table[$valeur]</td><td>
    Voici le code d'erreur qui s'affiche:

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: est-il in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Notice: Undefined offset: 1 in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: possible in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: que in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: la in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: fonction in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: array in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: multisort in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: trie in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: les in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: autres in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: clés in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: selon in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: clé in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: dans in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: le in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: premier in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: paramétre in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: en in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: donnant in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: variable in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: tableau in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: directement in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: deuxiéme in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: En in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: effet in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: je in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: ne in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: saurai in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: pas in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: combien in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: de in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: il in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: y in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: aura in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313

    Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 312

    Notice: Undefined index: mon in C:\xampp\htdocs\txtmining\Analyseur_texte.php on line 313
    ???

  4. #4
    Expert confirmé Avatar de papajoker
    Homme Profil pro
    Développeur Web
    Inscrit en
    Septembre 2013
    Messages
    2 201
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nièvre (Bourgogne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Septembre 2013
    Messages : 2 201
    Points : 4 665
    Points
    4 665
    Par défaut
    asort($occ) tout simplement !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    ...
    <th style="width:21%"><a href="?sens=asc">up</a> Nombre d'occurences <a href="?sens=desc">down</a> </th>
    ...
    <?php 
        $sens= (isset($_GET['sens'])&&($_GET['sens']=='asc'))  ? asort($occ) : arsort($occ);
        foreach($occ as $cle=>$valeur) 
        { 
              echo "<tr><td><a href='#'>$cle</a></td><td>$valeur</td><td></td></tr>";
        }
    ?>
    ps : pour la largeur des <tr> le total doit faire 100%

  5. #5
    Membre du Club
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Décembre 2010
    Messages
    118
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 118
    Points : 54
    Points
    54
    Par défaut
    Merci Papajoker c'est géniale

  6. #6
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Points : 91 220
    Points
    91 220
    Billets dans le blog
    20
    Par défaut
    Pour ton info, dans ton premier code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    foreach ($tab as $word)
    $word correspond aux valeurs de ton tableau, pas aux clés. Ce qui explique les messages d'erreur.

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

Discussions similaires

  1. [WD10] Afficher des valeurs dans un tableau
    Par dj-julio dans le forum WinDev
    Réponses: 4
    Dernier message: 19/03/2014, 11h32
  2. Réponses: 13
    Dernier message: 01/02/2006, 12h00
  3. [Tableaux]Ajouter des valeurs dans un tableau
    Par Antoine1183 dans le forum Collection et Stream
    Réponses: 13
    Dernier message: 03/04/2005, 13h41
  4. [VB6] recuperer des valeurs ds un tableau html avec vb!!
    Par leo13 dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 11/12/2004, 13h02
  5. Décaler des valeurs dans un tableau
    Par sh2003 dans le forum Langage
    Réponses: 6
    Dernier message: 20/03/2004, 16h01

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