tdphp/td3/3.php
2023-03-06 06:21:44 -08:00

22 lines
484 B
PHP

<?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/>";
}