Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2.  
  3. class Personne {
  4.  
  5. public $nom;
  6. public $prenom;
  7. public $adresse;
  8. public $date_naiss;
  9. public $age;
  10.  
  11. //public $nom = 'QUOUILLAULT';
  12. //public $prenom = 'Ludovic';
  13. //public $adresse = '11 rue du Martinet 28190 ST LUPERCE';
  14. //public $date_naiss = '21/11/1966';
  15.  
  16. public function __construct($nom,$prenom,$adresse,$date_naiss){
  17. $this->nom = $nom;
  18. $this->prenom = $prenom;
  19. $this->adresse = $adresse;
  20. $this->date_naiss = $date_naiss;
  21. }
  22.  
  23. public function afficher() {
  24. echo 'nom:'.$this->nom.' prenom:'.$this->prenom.' adresse:'.$this->adresse.' date_naiss:'.$this->date_naiss;
  25. }
  26.  
  27.  
  28. }
  29.  
  30. function Age($date_naissance)
  31. {
  32. $arr1 = explode('/', $date_naissance);
  33. $arr2 = explode('/', date('d/m/Y'));
  34.  
  35. if(($arr1[1] < $arr2[1]) || (($arr1[1] == $arr2[1]) && ($arr1[0] <= $arr2[0])))
  36. return $arr2[2] - $arr1[2];
  37.  
  38. return $arr2[2] - $arr1[2] - 1;
  39. }
  40.  
  41.  
  42. $personne1 = new Personne('QUOUILLAULT','Ludovic','11 rue du Martinet 28190 ST LUPERCE','21/11/1966');
  43.  
  44. $personne1->afficher();
  45.  
  46. $ma_date_de_naissance = '21/11/1966';
  47. $mon_age = Age($ma_date_de_naissance);
  48.  
  49. echo ' age='.$mon_age;
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement