Guest User

Untitled

a guest
Jan 24th, 2020
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>TP3</title>
  6. </head>
  7. <body>
  8.  
  9. <h1>Chaînes et Tableaux</h1>
  10.  
  11. <h2>Les Chaînes</h2>
  12. <h3>Question 1:</h3>
  13.  
  14. <?php
  15. $identite = array('alain', 'basile', 'David','Edgar');
  16. $age = array(1,15,35,65);
  17. $mail = array('moi.meme@gtail.be', 'truc@bruce.zo','caro@caramel.org','trop@monmel.fr');
  18.  
  19.  
  20. function aleatoire($identite, $age, $mail) {
  21.  
  22. echo "Je me nomme ";
  23. echo ucfirst($identite[rand(0,sizeof($identite)-1)])." j'ai ";
  24. echo $age[rand(0,sizeof($age)-1)]." ans et mon mail est ";
  25. echo $mail[rand(0,sizeof($mail)-1)]. " du domaine ";
  26.  
  27. extraction($mail[rand(0,sizeof($mail)-1)]);
  28. }
  29.  
  30.  
  31. function extraction($mail) {
  32.  
  33. $mydomain = explode('@', $mail);
  34. $myExtension = explode('.', $mydomain[1]);
  35. $fdomain = $myExtension[0];
  36. $extension = $myExtension[1];
  37.  
  38. echo $fdomain." avec l'extension ".$extension.'.<br>';
  39. }
  40.  
  41.  
  42. aleatoire($identite,$age,$mail)
  43.  
  44.  
  45. ?>
  46.  
  47. <h3>Question 2:</h3>
  48.  
  49. <p>Appliqué à la première question</p>
  50.  
  51. <h3>Question 3: </h3>
  52.  
  53. <?php
  54.  
  55. $people = array("Daniel", "Amandine", "daniel", "Zoé", "Zoé", "Tristan","véronique");
  56. $fruitpeople = new ArrayObject($people);
  57. $fruitpeople -> asort();
  58. foreach ($fruitpeople as $value) {
  59. echo $value.' ';
  60. }
  61.  
  62. ?>
  63.  
  64. <h3>Question 4:</h3>
  65.  
  66. <?php
  67.  
  68. foreach ($people as $value) {
  69. $value = ucfirst($value);
  70. $peopleTemp = array();
  71. if(in_array($value,$peopleTemp,TRUE)) {
  72.  
  73. $peopleTemp[$value] = 1
  74.  
  75. } else {
  76. $peopleTemp[$value] += 1;
  77. }
  78.  
  79. var_dump($peopleTemp);
  80. }
  81.  
  82.  
  83.  
  84. ?>
  85.  
  86.  
  87. </body>
  88. </html>
RAW Paste Data