commit 90f8d78bf731ff10546a614a5491bd12833e989c
Author: mael <mael@gnous.eu>
Date:   Mon Mar 6 06:21:44 2023 -0800

    first commit

diff --git a/10.php b/10.php
new file mode 100644
index 0000000..de7bd85
--- /dev/null
+++ b/10.php
@@ -0,0 +1,27 @@
+<?php
+
+$tableau = array(
+    "nom" => "nunes",
+    "prenom" => "Jean-Claude",
+    "age" => 18,
+    "addresse" => "35400 Saint-Malo",
+    "profession" => "Java",
+);
+
+echo "<hr><h1>FOR :</h1>";
+
+for ($i = 0; $i < count($tableau); $i++) {
+    print(array_keys($tableau)[$i] . ": ");
+    echo $tableau[array_keys($tableau)[$i]] . "<br/>";
+}
+
+echo "<hr><h1>PRINT_R :</h1>";
+
+print_r($tableau);
+
+
+echo "<hr><h1>FOREACH :</h1>";
+
+foreach ($tableau as $key => $value) {
+    echo "$key: $value<br/>";
+}
diff --git a/11.php b/11.php
new file mode 100644
index 0000000..00ea723
--- /dev/null
+++ b/11.php
@@ -0,0 +1,39 @@
+<?php
+
+$tableau = array(
+    "jean" => 14,
+    "claude" => 13,
+    "david" => 18,
+    "maxime" => 1,
+);
+
+$moyenne = 0;
+
+foreach ($tableau as $prenom => $note) {
+    echo "$prenom: $note<br/>";
+    $moyenne += $note;
+}
+
+$moyenne = $moyenne / count($tableau);
+
+echo "<p><strong>Moyenne :</strong> $moyenne";
+
+// Modification des notes 
+foreach ($tableau as $prenom => $note) {
+    if ($prenom == "jean") {
+        continue;
+    }
+    $tableau[$prenom] = $note - 2;
+}
+
+echo "<hr><h3>Nouvelles notes</h3>";
+
+?>
+
+<pre>
+
+<?php
+print_r($tableau);
+?>
+
+</pre>
\ No newline at end of file
diff --git a/2.php b/2.php
new file mode 100644
index 0000000..84989b1
--- /dev/null
+++ b/2.php
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <?php 
+        echo "<h1>Bonjour à tous</h1>";
+        echo "<p>Salut <a href='lien'>lien</a></p>";
+    ?> 
+</body>
+</html>
+
+<!-- 
+    Code source : 
+
+<!DOCTYPE html>
+<html>
+<body>
+    <h1>Bonjour à tous</h1><p>Salut <a href='lien'>lien</a></p> 
+</body>
+</html>
+
+--> 
\ No newline at end of file
diff --git a/3.php b/3.php
new file mode 100644
index 0000000..f2b80ef
--- /dev/null
+++ b/3.php
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <?php 
+        $var = "a";
+        $var2 = 23;
+        echo $var; 
+        echo "<br/>";
+        echo $var2;
+
+        echo $var." : bonjour !";
+    ?> 
+</body>
+</html>
diff --git a/4.php b/4.php
new file mode 100644
index 0000000..6c26932
--- /dev/null
+++ b/4.php
@@ -0,0 +1,9 @@
+<?php 
+
+$var_a = 10;
+
+$var_b = 20;
+
+echo $var_a * $var_b . "<br/>";
+
+echo $var_b + $var_a . "<br/>";
\ No newline at end of file
diff --git a/5.php b/5.php
new file mode 100644
index 0000000..4b14006
--- /dev/null
+++ b/5.php
@@ -0,0 +1,10 @@
+<?php 
+$prenom = "Jean";
+$nom = "Claude";
+$addr = "18 Rue des écoles"; 
+$age = 48; 
+
+echo "<p>Prenom : $prenom - Nom : $nom - Addresse : $addr - Age : $age</p><br/>";
+
+echo ($age / 10) % 10;
+?>
\ No newline at end of file
diff --git a/6.php b/6.php
new file mode 100644
index 0000000..93eaaf8
--- /dev/null
+++ b/6.php
@@ -0,0 +1,3 @@
+<?php 
+
+echo($_SERVER["REMOTE_ADDR"]);
diff --git a/7.php b/7.php
new file mode 100644
index 0000000..e4c6537
--- /dev/null
+++ b/7.php
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <pre>
+<?php $var = "a";
+$var2 = 23;
+print_r($var . "<br/>");
+print_r($var2); ?> 
+    </pre>
+</body>
+</html>
diff --git a/8.php b/8.php
new file mode 100644
index 0000000..2ae6bb2
--- /dev/null
+++ b/8.php
@@ -0,0 +1,13 @@
+<?php
+
+$prenom = "Jean";
+$nom = "Petit";
+$age = 5;
+
+echo "<p>Prénom : $prenom<br/>Nom : $nom</p>";
+
+if ($age < 18) {
+    echo "$prenom est mineur(e).";
+} else {
+    echo "$prenom est majeur(e).";
+}
diff --git a/9.php b/9.php
new file mode 100644
index 0000000..9a5e393
--- /dev/null
+++ b/9.php
@@ -0,0 +1,24 @@
+<?php
+
+for ($i = 2004; $i <= 2022; $i++) {
+    echo "$i<br/>";
+}
+
+echo "<br/><br/>";
+
+$k = 2004;
+
+while ($k <= 2022) {
+    echo "$k<br/>";
+    $k++;
+}
+
+$k = 2004;
+
+echo "<br/><br/>";
+
+
+do {
+    echo "$k<br/>";
+    $k++;
+} while ($k <= 2022);
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..9049724
--- /dev/null
+++ b/index.php
@@ -0,0 +1,3 @@
+<?php
+echo "bonjour";
+?>
\ No newline at end of file
diff --git a/td3/1.php b/td3/1.php
new file mode 100644
index 0000000..c9f14a1
--- /dev/null
+++ b/td3/1.php
@@ -0,0 +1,13 @@
+<?php
+
+$resultat = array();
+
+for ($i = 0; $i < rand(10, 20); $i++) {
+    array_push($resultat, rand(0, 15));
+}
+
+print_r($resultat);
+
+print("<p>Nombre d'élements dans resultat (count) : " . count($resultat));
+
+print("<p>Nombre d'élements dans resultat (sizeof) : " . sizeof($resultat));
diff --git a/td3/10.php b/td3/10.php
new file mode 100644
index 0000000..46aef51
--- /dev/null
+++ b/td3/10.php
@@ -0,0 +1,13 @@
+<?php
+
+function minmax($a)
+{
+    $valmin = min($a);
+    $valmax = max($a);
+    return array(
+        "min" => $valmin,
+        "max" => $valmax
+    );
+}
+
+print_r(minmax(array(1, 24, 5, 9, 10, 2222, 291, 20)));
diff --git a/td3/11.php b/td3/11.php
new file mode 100644
index 0000000..e41ce9b
--- /dev/null
+++ b/td3/11.php
@@ -0,0 +1,22 @@
+<?php
+
+function minmax($a)
+{
+    $valmin = min($a);
+    $valmax = max($a);
+    return array(
+        "min" => $valmin,
+        "max" => $valmax
+    );
+}
+
+print_r(minmax(array(
+    "maxime" => 1,
+    "coutteau" => 24,
+    "jean" => 5,
+    "claude" => 9,
+    "nunes" => 10,
+    "david" => 2222,
+    "gatel" => 291,
+    "frederic" => 20
+)));
diff --git a/td3/13.php b/td3/13.php
new file mode 100644
index 0000000..e6ca7c7
--- /dev/null
+++ b/td3/13.php
@@ -0,0 +1,36 @@
+<?php
+
+// Tableau contenant une liste d'emails
+$emails = array(
+    "frederic.weis@univ-rennes1.fr",
+    "david.gatel@univ-rennes1.fr",
+    "mael.gramain@etudiant.univ-rennes1.fr",
+    "alice.wonderland@hotmail.com",
+    "charlie.brown@example.com",
+    "samantha.jones@yahoo.com",
+    "david.johnson@example.com"
+);
+
+// Tableau contenant les noms de domaines correspondant aux adresses mails
+$domains = array();
+foreach ($emails as $email) {
+    $parts = explode("@", $email);
+    $domain = $parts[1];
+    $domains[] = $domain;
+}
+
+// Calcul du pourcentage d'emails proposés par chaque nom de domaine
+$counts = array_count_values($domains);
+$total = array_sum($counts);
+$percentages = array();
+foreach ($counts as $domain => $count) {
+    $percentage = ($count / $total) * 100;
+    $percentages[$domain] = $percentage;
+}
+
+// Affichage des résultats
+echo "Liste d'emails : <br/>" . implode(",<br/>", $emails) . "<br/><br/>";
+echo "Noms de domaines correspondants : " . implode(", ", $domains) . "<br/><br/>";
+foreach ($percentages as $domain => $percentage) {
+    echo "Pourcentage d'emails proposés par " . $domain . " : " . round($percentage, 2) . "%<br/>";
+}
diff --git a/td3/15.php b/td3/15.php
new file mode 100644
index 0000000..55b84fd
--- /dev/null
+++ b/td3/15.php
@@ -0,0 +1,4 @@
+<?php
+// Return current date from the remote server
+$date = date('d-m-y h:i:s');
+echo $date;
diff --git a/td3/16.php b/td3/16.php
new file mode 100644
index 0000000..0ba9a93
--- /dev/null
+++ b/td3/16.php
@@ -0,0 +1,32 @@
+<?php
+// Création d'un tableau associatif
+$fruits = array(
+    "pomme" => 2,
+    "orange" => 3,
+    "banane" => 1,
+    "fraise" => 4
+);
+
+// Création d'un tableau trié selon les valeurs
+$valTri = $fruits; // on copie le tableau initial pour ne pas le modifier
+asort($valTri);
+
+// Création d'un tableau trié selon les clés
+$keyTri = $fruits; // on copie le tableau initial pour ne pas le modifier
+ksort($keyTri);
+
+// Affichage des trois tableaux
+echo "Tableau initial :<br>";
+print_r($fruits);
+echo "<br>";
+
+echo "Tableau trié selon les valeurs :<br>";
+print_r($valTri);
+echo "<br>";
+
+echo "Tableau trié selon les clés :<br>";
+print_r($keyTri);
+echo "<br>";
+
+// Vérification que l'association clé valeur est maintenue
+echo "L'association clé valeur est maintenue : " . ($fruits == $keyTri && $fruits == $valTri ? "Oui" : "Non");
diff --git a/td3/17.php b/td3/17.php
new file mode 100644
index 0000000..4978068
--- /dev/null
+++ b/td3/17.php
@@ -0,0 +1,17 @@
+<?php
+
+// Création du tableau associatif
+$fruits = array(
+    "pomme" => 3,
+    "orange" => 2,
+    "banane" => 4,
+    "kiwi" => 1
+);
+
+// Tri du tableau associatif dans l'ordre décroissant
+arsort($fruits);
+
+// Affichage du tableau trié
+foreach($fruits as $fruit => $quantite) {
+    echo $fruit . " : " . $quantite . "<br>";
+}
diff --git a/td3/18.php b/td3/18.php
new file mode 100644
index 0000000..876b77c
--- /dev/null
+++ b/td3/18.php
@@ -0,0 +1,17 @@
+<?php
+
+function affiche_tab($tab) {
+    echo "<table>";
+    foreach($tab as $cle => $valeur) {
+        echo "<tr><td>" . $cle . "</td><td>" . $valeur . "</td></tr>";
+    }
+    echo "</table>";
+}
+
+// Exemple d'utilisation de la fonction
+$mon_tab = array(
+    "nom" => "Dupont",
+    "prenom" => "Jean",
+    "age" => 35
+);
+affiche_tab($mon_tab);
diff --git a/td3/19.php b/td3/19.php
new file mode 100644
index 0000000..dea9127
--- /dev/null
+++ b/td3/19.php
@@ -0,0 +1,22 @@
+<?php
+
+function calculatrice($a, $b, $operateur) {
+    switch($operateur) {
+        case "+":
+            return $a + $b;
+        case "-":
+            return $a - $b;
+        case "*":
+            return $a * $b;
+        case "/":
+            return $a / $b;
+        case "%":
+            return $a % $b;
+        default:
+            return "Opérateur non reconnu";
+    }
+}
+
+// Exemple d'utilisation de la fonction
+$resultat = calculatrice(5, 3, "+");
+echo "5 + 3 = " . $resultat;
diff --git a/td3/2.php b/td3/2.php
new file mode 100644
index 0000000..279d653
--- /dev/null
+++ b/td3/2.php
@@ -0,0 +1,13 @@
+<?php
+
+$tableau = array(10, 29, 19, 82, 10, 85);
+
+$nb = 29;
+
+if (in_array($nb, $tableau)) {
+    echo ("<p>$nb est présent dans le tableau</p>");
+}
+
+if (array_search($nb, $tableau)) {
+    echo ("<p>$nb est présent dans le tableau</p>");
+}
diff --git a/td3/20.php b/td3/20.php
new file mode 100644
index 0000000..e69de29
diff --git a/td3/3.php b/td3/3.php
new file mode 100644
index 0000000..399e554
--- /dev/null
+++ b/td3/3.php
@@ -0,0 +1,22 @@
+<?php
+
+$tab = array(2, 4, 6, 4, 8, 2, 5, 6, 4);
+
+echo "<h2>Tableau :</h2>";
+foreach ($tab as $val) {
+    echo "$val ";
+}
+echo "<br/>";
+
+$count = array_count_values($tab);
+echo "<h2>Occurrences :</h2>";
+foreach ($count as $val => $occ) {
+    echo "$val : $occ<br/>";
+}
+
+// Créer un tableau listant les différentes valeurs présentes dans le tableau d'origine
+$distinct = array_keys($count);
+echo "<h2>Valeurs distinctes :</h2>";
+foreach ($distinct as $val) {
+    echo "$val<br/>";
+}
diff --git a/td3/4.php b/td3/4.php
new file mode 100644
index 0000000..e1fba16
--- /dev/null
+++ b/td3/4.php
@@ -0,0 +1,8 @@
+<pre>
+<?php
+
+$tableau = array_fill(0,  102, "JEAN-CLAUDE NUNES !");
+
+print_r($tableau);
+?>
+</pre>
\ No newline at end of file
diff --git a/td3/5.php b/td3/5.php
new file mode 100644
index 0000000..d0aa931
--- /dev/null
+++ b/td3/5.php
@@ -0,0 +1,9 @@
+<?php
+
+$tableau = array();
+
+foreach (range(1, 100) as $val) {
+    array_push($tableau, $val);
+}
+
+print_r($tableau);
diff --git a/td3/6.php b/td3/6.php
new file mode 100644
index 0000000..cdea1f8
--- /dev/null
+++ b/td3/6.php
@@ -0,0 +1,54 @@
+<?php
+
+$tableau = array();
+
+// Écrire un programme permettant de créer un tableau d’entiers variant de 0 à 63 (utiliser range() ),
+
+foreach (range(1, 63) as $val) {
+    array_push($tableau, $val);
+}
+
+// puis de créer un second tableau à partir du premier avec de nombres variant de 0 à 6.3.
+$tableau2 = array();
+foreach ($tableau as $identifiant => $valeur) {
+    $tableau2[$identifiant] = $valeur / 10;
+}
+
+// Créer ensuite un troisième tableau associatif dont les clés X varient de 0 à 6.3 et dont les valeurs sont sin(X).
+$tableau3 = array();
+foreach ($tableau2 as $identifiant => $valeur) {
+    $tableau3[$valeur] = sin($valeur);
+}
+
+?>
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+    <style>
+        table * {
+            border: 1px solid red;
+        }
+    </style>
+</head>
+
+<body>
+    <table>
+        <tr>
+            <th>Clé</th>
+            <th>Valeur</th>
+        </tr>
+        <?php
+        //Afficher le tableau de valeurs dans un tableau HTML <table>.
+        foreach ($tableau3 as $identifiant => $valeur) {
+            echo "<tr><td>$identifiant</td><td>$valeur</td></tr>";
+        }
+        ?>
+    </table>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/td3/7.php b/td3/7.php
new file mode 100644
index 0000000..718e430
--- /dev/null
+++ b/td3/7.php
@@ -0,0 +1,14 @@
+<?php
+
+$tableau = array(
+    "jean-claude" => "nunes",
+    "philippe" => "ferrey",
+    "david" => "gatel",
+    "frederic" => "weis",
+    "flavien" => "motta",
+    "maxime" => "coutteau"
+);
+
+$cle = array_search("nunes", $tableau);
+
+echo $cle;
diff --git a/td3/8.php b/td3/8.php
new file mode 100644
index 0000000..fc3090d
--- /dev/null
+++ b/td3/8.php
@@ -0,0 +1,16 @@
+<?php
+$valeur = 12;
+
+function calc($valeur)
+{
+    $pow = pow($valeur, 2);
+    $abs = abs($valeur);
+    $sqrt = sqrt($valeur);
+    return [$pow, $abs, $sqrt];
+}
+
+$resultats = calc($valeur);
+
+echo "La puissance de $valeur à la 2ème est : " . $resultats[0] . "<br/>";
+echo "La valeur absolue de $valeur est : " . $resultats[1] . "<br/>";
+echo "La racine carrée de $valeur est : " . $resultats[2] . "<br/>";
diff --git a/td3/9.php b/td3/9.php
new file mode 100644
index 0000000..b9fe1f4
--- /dev/null
+++ b/td3/9.php
@@ -0,0 +1,13 @@
+<?php
+
+function minmax($a, $b)
+{
+    $valmin = min($a, $b);
+    $valmax = max($a, $b);
+    return array(
+        "min" => $valmin,
+        "max" => $valmax
+    );
+}
+
+print_r(minmax(35, 1));