first commit
This commit is contained in:
commit
90f8d78bf7
29 changed files with 499 additions and 0 deletions
27
10.php
Normal file
27
10.php
Normal file
|
@ -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/>";
|
||||
}
|
39
11.php
Normal file
39
11.php
Normal file
|
@ -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>
|
21
2.php
Normal file
21
2.php
Normal file
|
@ -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>
|
||||
|
||||
-->
|
14
3.php
Normal file
14
3.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<?php
|
||||
$var = "a";
|
||||
$var2 = 23;
|
||||
echo $var;
|
||||
echo "<br/>";
|
||||
echo $var2;
|
||||
|
||||
echo $var." : bonjour !";
|
||||
?>
|
||||
</body>
|
||||
</html>
|
9
4.php
Normal file
9
4.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
$var_a = 10;
|
||||
|
||||
$var_b = 20;
|
||||
|
||||
echo $var_a * $var_b . "<br/>";
|
||||
|
||||
echo $var_b + $var_a . "<br/>";
|
10
5.php
Normal file
10
5.php
Normal file
|
@ -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;
|
||||
?>
|
3
6.php
Normal file
3
6.php
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
echo($_SERVER["REMOTE_ADDR"]);
|
11
7.php
Normal file
11
7.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<?php $var = "a";
|
||||
$var2 = 23;
|
||||
print_r($var . "<br/>");
|
||||
print_r($var2); ?>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
13
8.php
Normal file
13
8.php
Normal file
|
@ -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).";
|
||||
}
|
24
9.php
Normal file
24
9.php
Normal file
|
@ -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);
|
3
index.php
Normal file
3
index.php
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
echo "bonjour";
|
||||
?>
|
13
td3/1.php
Normal file
13
td3/1.php
Normal file
|
@ -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));
|
13
td3/10.php
Normal file
13
td3/10.php
Normal file
|
@ -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)));
|
22
td3/11.php
Normal file
22
td3/11.php
Normal file
|
@ -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
|
||||
)));
|
36
td3/13.php
Normal file
36
td3/13.php
Normal file
|
@ -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/>";
|
||||
}
|
4
td3/15.php
Normal file
4
td3/15.php
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
// Return current date from the remote server
|
||||
$date = date('d-m-y h:i:s');
|
||||
echo $date;
|
32
td3/16.php
Normal file
32
td3/16.php
Normal file
|
@ -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");
|
17
td3/17.php
Normal file
17
td3/17.php
Normal file
|
@ -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>";
|
||||
}
|
17
td3/18.php
Normal file
17
td3/18.php
Normal file
|
@ -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);
|
22
td3/19.php
Normal file
22
td3/19.php
Normal file
|
@ -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;
|
13
td3/2.php
Normal file
13
td3/2.php
Normal file
|
@ -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>");
|
||||
}
|
0
td3/20.php
Normal file
0
td3/20.php
Normal file
22
td3/3.php
Normal file
22
td3/3.php
Normal file
|
@ -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/>";
|
||||
}
|
8
td3/4.php
Normal file
8
td3/4.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<pre>
|
||||
<?php
|
||||
|
||||
$tableau = array_fill(0, 102, "JEAN-CLAUDE NUNES !");
|
||||
|
||||
print_r($tableau);
|
||||
?>
|
||||
</pre>
|
9
td3/5.php
Normal file
9
td3/5.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
$tableau = array();
|
||||
|
||||
foreach (range(1, 100) as $val) {
|
||||
array_push($tableau, $val);
|
||||
}
|
||||
|
||||
print_r($tableau);
|
54
td3/6.php
Normal file
54
td3/6.php
Normal file
|
@ -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>
|
14
td3/7.php
Normal file
14
td3/7.php
Normal file
|
@ -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;
|
16
td3/8.php
Normal file
16
td3/8.php
Normal file
|
@ -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/>";
|
13
td3/9.php
Normal file
13
td3/9.php
Normal file
|
@ -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));
|
Loading…
Reference in a new issue