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 :

Trier un array particulier


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut Trier un array particulier
    Bonjour,

    J'ai deux chaines de caractere:

    - le premiere (en eho) variable $rc

    r1c1|r1c2|r1c3|r1c4|r1c5|r1c6|r1c7|r2c1|r2c2|r2c3|r2c4|r2c5|r2c6|r2c7|r2c8

    - le deuxieme (tjrs en echo) variable $heure

    1350|1424|1452|1522|1552|1620|1650|1200|1230|1300|1332|1405|1437|1505|1535

    je n'arrive pas a trier la variable $heure par odre croissant en concervant la $rc qui va avec.

    Je m'explique je cherche à faire une $variable finale comme cela :

    r2c2|1200|r2c3|1230|r2c4|1300|r2c5|1332|r1c1|1350| etc...
    bref un classement sur l'heure.

    Rassurez vous j'ai tout essayé mais rien...

    j'ai essayé avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    $axe = array("$rc" => "$heure");
    asort($axe);
    foreach ($faxe as $key => $val) {
        echo "$key = $val\n";
    mais rien ne fonctionne.
    Je suis proche du coma de code.
    HELP

    Merci d'avance.

  2. #2
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Salut,

    comme ça :
    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
    <?php
     
    $rc    = 'r1c1|r1c2|r1c3|r1c4|r1c5|r1c6|r1c7|r2c1|r2c2|r2c3|r2c4|r2c5|r2c6|r2c7|r2c8';
    $heure = '1350|1424|1452|1522|1552|1620|1650|1200|1230|1300|1332|1405|1437|1505|1535';
     
    $data = array_combine(
        explode('|', $rc),
        explode('|', $heure)
    );
     
    asort($data);
     
    $elems = array();
    foreach($data as $k => $v) {
         $elems[] = $k;
         $elems[] = $v;
    }
     
    $str = implode('|', $elems);
     
    ?>

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut merci mais j'ai une erreur !
    Fatal error: Call to undefined function: array_combine()
    merci bcp pour ta patience a mon egart.

    Cdlt

  4. #4
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    quelle version de PHP tu utilises ?

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut merci
    désolé mais du php 4

  6. #6
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    ouch !!

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut merci
    Peux t on avoir deux repertoire different sur un serveur avec htacces different ?

  8. #8
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    On peut créer une fonction array_combine() pour le PHP 4 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    function array_combine($arr1, $arr2)
    {
        $data = array();
        foreach($arr1 as $k => $v) {
            $data[$v] = $arr2[$k];
        }
        return $data;
    }
    Le reste ne change pas

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut [Resolu] merci
    profil bas maître

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

Discussions similaires

  1. Trier un Array un peu particulier
    Par krapoulos dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 16/10/2011, 03h18
  2. trier un fichier particulier command sort shell
    Par Mistervanhalen dans le forum Shell et commandes GNU
    Réponses: 9
    Dernier message: 22/06/2008, 18h56
  3. [Tableaux] trier plusieurs array
    Par djedje37et28 dans le forum Langage
    Réponses: 5
    Dernier message: 29/03/2007, 10h44
  4. [Tableaux] Comment trier un array multidimensionel ?
    Par kaptnkill dans le forum Langage
    Réponses: 2
    Dernier message: 26/09/2006, 09h31
  5. [Tableaux] Trier un array
    Par borgfabr dans le forum Langage
    Réponses: 11
    Dernier message: 23/04/2006, 15h13

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