Foreach avec 3 tableaux

Résolu
Fornikator -  
avion-f16 Messages postés 19182 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

J'airais traiter 3 array pour 1 seul affichage, donc j'ai fait comme ça mais cela ne fonctionne pas correctement, comment faire ?

foreach($_POST['titre']  as $titre) {
foreach($_POST['nom'] as $nom) {
foreach($_POST['url'] as $url) {
echo '<chanson nom="'.$titre.'" auteur="'.$nom.'" place="'.$i++.'" fichier="'.$url.'" />'."\n";
}
}
}


Merci d'avance.

1 réponse

  1. avion-f16 Messages postés 19182 Date d'inscription   Statut Contributeur Dernière intervention   4 511
     
    <?php
    $chansons = array();
    
    $i = 0;
    foreach($_POST['titre'] as $titre) {
        $chansons[$i]['titre'] = $titre;
        $chansons[$i]['nom'] = $_POST['nom'][$i];
        $chansons[$i]['url'] = $_POST['url'][$i];
    
        $i++;
    }
    unset($i);
    
    foreach($chansons as $chanson) {
        echo 'Titre : '.$chanson['titre'].'<br />'."\n"
         . 'Nom : '.$chanson['nom'].'<br />'."\n"
         . 'URL : '.$chanson['url'].'<br />';
    }
    ?>
    2