tdphp/td3/3.php

23 lines
484 B
PHP
Raw Normal View History

2023-03-06 15:21:44 +01:00
<?php
$tab = array(2, 4, 6, 4, 8, 2, 5, 6, 4);
echo "<h2>Tableau :</h2>";
foreach ($tab as $val) {
echo "$val ";
}
echo "<br/>";
$count = array_count_values($tab);
echo "<h2>Occurrences :</h2>";
foreach ($count as $val => $occ) {
echo "$val : $occ<br/>";
}
// Créer un tableau listant les différentes valeurs présentes dans le tableau d'origine
$distinct = array_keys($count);
echo "<h2>Valeurs distinctes :</h2>";
foreach ($distinct as $val) {
echo "$val<br/>";
}