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] Trier un array [FAQ]


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    102
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Avril 2002
    Messages : 102
    Par défaut [Tableaux] Trier un array
    Bonjour !

    J'aimerai trier un arry 2 dimensions en fonction du nom de la colonne. Existe-il une méthode ou est-ce que je dois l'écrire moi ?

    Voici comment je rempli mon tableau via une boucle :

    tabStats[$i]['nbPenalitesChamp'] = $nbPenChamp ;
    tabStats[$i]['nbPenalitesTourn'] = $nbPenTourn ;
    tabStats[$i]['nbPenalitesTotal'] = $nbPenChamp + $nbPenTourn ;

    tabStats[$i]['nbPenalitesMatchChamp'] = $nbPenMatchChamp ;
    tabStats[$i]['nbPenalitesMatchTourn'] = $nbPenMatchTourn ;
    tabStats[$i]['nbPenalitesMatchTotal'] = $nbPenMatchChamp +$nbPenMatchTourn ;

  2. #2
    Membre éclairé Avatar de renaudjuif
    Inscrit en
    Avril 2006
    Messages
    325
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 325
    Par défaut
    as tu été voir du côté de array_multisort ?
    http://es2.php.net/manual/fr/functio...-multisort.php

  3. #3
    Membre éprouvé
    Avatar de Anduriel
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Février 2004
    Messages
    2 290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Février 2004
    Messages : 2 290
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <?php
       sort($tabStats[$i], SORT_STRING);
    ?>

  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
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    function compare($a, $b) {
       return strnatcasecmp($a['nbPenalitesMatchChamp'], $b['nbPenalitesMatchChamp']);
    }
    usort(tabStats, 'compare');

  5. #5
    Membre éprouvé
    Avatar de Anduriel
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Février 2004
    Messages
    2 290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Février 2004
    Messages : 2 290
    Par défaut
    J'ai remarqué que tu aimais bien usort()

  6. #6
    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
    Ben c'est extremement simple et pratique et j'ai jamais chercher à comprendre comment utiliser array_multisort

Discussions similaires

  1. [Tableaux] trier plusieurs array
    Par djedje37et28 dans le forum Langage
    Réponses: 5
    Dernier message: 29/03/2007, 10h44
  2. [Tableaux] Comment trier un array multidimensionel ?
    Par kaptnkill dans le forum Langage
    Réponses: 2
    Dernier message: 26/09/2006, 09h31
  3. [Tableaux] Trier un tableau [array]
    Par clemsouz dans le forum Langage
    Réponses: 2
    Dernier message: 15/05/2006, 13h33
  4. [Tableaux] Trier un tableau comme avec ORDER BY DESC
    Par Anduriel dans le forum Langage
    Réponses: 28
    Dernier message: 08/12/2005, 18h50
  5. [Tableaux] Gérer une array...
    Par kult dans le forum Langage
    Réponses: 7
    Dernier message: 16/11/2005, 17h03

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