Bonjour,

J'aimerais ajouter la valeur "cd456" dans le tableau $identifiant qui a pour valeur que "ab123" au début.

J'ai écrit ce code, mais aucun n'ajout se fait...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
    class Utilisateur {
            // attributs :
            var $nom;
            var $prenom;
            var $age;
            var $identifiant = array();
            // constructeur :
            function Utilisateur($nom, $prenom, $age, $identifiant) {
                $this->nom = $nom;
                $this->prenom = $prenom;
                $this->age = $age;
                $this->ide = $identifiant;              
 
            }
            // méthodes diverses :
            function affiche() {
   echo "Nom : $this->nom".'<br />'."Prénom : $this->prenom".'<br />'."Age : $this->age".'<br />'."Identifiant : $this->ide";
            }
            function ajout_com($id) {
                $identifiant[] = $id;
            }
 
        }
 
 
        $p = new Utilisateur("Mahe","Gael","60","ab123");
        $p->affiche();
        echo '<br />';
        $p->ajout_com('cd456');
        $p->affiche();
        ?>
    </body>
</html>
Merci d'avance.