-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexo5.php
42 lines (33 loc) · 1.02 KB
/
exo5.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=, initial-scale=1.0">
<title>PHP PARTIE 2 : EXO 5</title>
</head>
<body>
<h1>EXO 5</h1>
<p>
Créer une fonction personnalisée permettant de créer un formulaire de champs de texte en
précisant le nom des champs associés.</p>
Exemple :<br>
$nomsInput = array("Nom","Prénom","Ville");<br>
afficherInput($nomsInput);
</p>
<br>
<hr>
<h2><u>SOLUTION DES EXERCICES</u>:</h2>
</body>
<?php
$input = ['Nom', 'Prénom', 'Ville']; // On boucle le tableau pour afficher les X inputs.
function afficherInput($input)
{
$affi = ''; // Bien concat tout sinon marche pas.
foreach ($input as $inp) {
$affi .= "<label for='$inp'><p>$inp</p>";
$affi .= "<input type='text' name='$inp'></label>";
}
return $affi;
}
echo afficherInput($input);