Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  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.  
  18.  
  19. function aleatoire($identite, $age, $mail) {
  20.  
  21. echo "Je me nomme ";
  22. echo ucfirst($identite[rand(0,sizeof($identite)-1)])." j'ai ";
  23. echo $age[rand(0,sizeof($age)-1)]." ans et mon mail est ";
  24. echo $mail[rand(0,sizeof($mail)-1)]. " du domaine ";
  25.  
  26. extraction($mail[rand(0,sizeof($mail)-1)]);
  27. }
  28.  
  29.  
  30. function extraction($mail) {
  31.  
  32. $mydomain = explode('@', $mail);
  33. $myExtension = explode('.', $mydomain[1]);
  34. $fdomain = $myExtension[0];
  35. $extension = $myExtension[1];
  36.  
  37. echo $fdomain." avec l'extension ".$extension.'.<br>';
  38. }
  39.  
  40.  
  41. aleatoire($identite,$age,$mail)
  42.  
  43.  
  44. ?>
  45.  
  46. <h3>Question 2:</h3>
  47.  
  48. <p>Appliqué à la première question</p>
  49.  
  50. <h3>Question 3: </h3>
  51.  
  52. <?php
  53.  
  54. $people = array("Daniel", "Amandine", "daniel", "Zoé", "Zoé", "Tristan","véronique");
  55. $fruitpeople = new ArrayObject($people);
  56. $fruitpeople -> asort();
  57. foreach ($fruitpeople as $value) {
  58. echo $value.' ';
  59. }
  60.  
  61. ?>
  62.  
  63. <h3>Question 4:</h3>
  64.  
  65. <?php
  66.  
  67. foreach ($people as $value) {
  68. $value = ucfirst($value);
  69. $peopleTemp = array();
  70. if(in_array($value,$peopleTemp,TRUE)) {
  71.  
  72. $peopleTemp[$value] = 1
  73.  
  74. } else {
  75. $peopleTemp[$value] += 1;
  76. }
  77.  
  78. var_dump($peopleTemp);
  79. }
  80.  
  81.  
  82.  
  83. ?>
  84.  
  85.  
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement