File "work02.php"

Full Path: /home/analogde/www/FTP/Monsta-FTP-master/Filtrage_version/work02.php
File size: 2.51 KB
MIME-type: text/x-php
Charset: utf-8

<?php

/*
Array
(
    [tableau_version_initial] => Array
        (
            [0] => fichier.txt
            [1] => autre_fichier.txt
            [2] => document.pdf
            [3] => image.png
            [4] => unique_file.docx
        )

    [tableau_version_liste] => Array
        (
            [fichier.txt] => Array
                (
                    [0] => fichier_v1.txt
                    [1] => fichier_v2.txt
                    [2] => fichier_v3.txt
                    [3] => fichier_v4.txt
                )

            [document.pdf] => Array
                (
                    [0] => document_v1.pdf
                )

            [image.png] => Array
                (
                    [0] => image_v1.png
                )

        )

)
*/

$data = [
    "tableau_version_initial" => [
        "fichier.txt",
        "autre_fichier.txt",
        "document.pdf",
        "image.png",
        "unique_file.docx"
    ],
    "tableau_version_liste" => [
        "fichier.txt" => [
            "fichier_v1.txt",
            "fichier_v2.txt",
            "fichier_v3.txt",
            "fichier_v4.txt"
        ],
        "document.pdf" => [
            "document_v1.pdf"
        ],
        "image.png" => [
            "image_v1.png"
        ]
    ]
];

$tableauVersionListe = $data["tableau_version_liste"];

// Afficher le sous-tableau (pour vérification)
echo "Sous-tableau 'tableau_version_liste':\n";
echo "<pre>";
print_r($tableauVersionListe);
echo "</pre>";


foreach ($data["tableau_version_liste"] as $key => $subArray) 
{
    $count = count($subArray);
    echo "La clé '$key' contient $count élément(s).\n";
}


$list_of_keys = array_keys($data["tableau_version_liste"]);
foreach ($list_of_keys as $key )
{
    echo "Compteur " .count ($data["tableau_version_liste"][$key] ) ."<br>";

    echo "---->>> " .$key ."<br>";
} 


$result = []; // Initialisation du tableau associatif

foreach ($tableauVersionListe as $key => $subArray) {
    $result[$key] = count($subArray); // Ajouter la clé avec le nombre d'éléments
}

// Affichage du tableau associatif résultant
print_r($result);

echo "Yes !";

/*
 // Parcourir le sous-tableau et écrire son contenu dans le fichier
 foreach ($tableauVersionListe as $key => $versions) 
 {
    
    echo "Key " .$key ."<br>";

    echo "NB " .count($tableauVersionList[$key]);

il fait recupérer le nom d'élément dans le sous tableau

    foreach ($versions as $version) 
    {
        //fwrite($file, "  - $version\n");
        echo "Contenu " .$version ."<br>";
    }
}   
*/
?>