I would like the sample output as below.
1: 2 occurrences
2: 3 occurrences
3: 2 occurrences
4: 1 occurrence
5: 1 occurrence
7: 1 occurrence
the number of occurrences is based on the user input in a form format. Below is the Html code that I use for the user to type in the number.
<!DOCTYPE html>
<html>
<style>
h1{
text-align:center;
}
form{
text-align:center;
margin:auto;
border-style: solid;
width:700px;
height:250px;
}
</style>
<body>
<form action="page2" method="get">
<h1>Algorithm Calculator</h1>
<label for="fname">Enter Number with Comma <br> eg:
1,2,3,4,4,5,5,7</label><br><br>
<input type="text" id="number" name="number"><br>
<br>
<input type="submit" value="Confirm">
</form>
</body>
</html>
Second-page code
<?php
$number=$_GET['number'];
$result = array();
$result = explode(',',$number);
foreach ($result as $value){
echo "$value = ".array_count_values($result)
[$value]." occurrences <br>";
}
?>
I only want my code to loop once but it loop more than once if the user input the same number twice. Below is my output.
1 = 1 occurrences
2 = 1 occurrences
3 = 1 occurrences
4 = 2 occurrences
4 = 2 occurrences (i do not want this to loop twice)
