Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Most Frequent Tag</title>
- </head>
- <body>
- <form action="" method="post">
- <div>Enter Tags</div>
- <input type="text" name="tags" />
- <input type="submit" />
- </form>
- <?php
- if (isset($_POST['tags'])) {
- $arr = explode(", ", $_POST['tags']);
- $tags = [];
- for ($i=0; $i < sizeof($arr); $i++) {
- if (array_key_exists($arr[$i], $tags)) {
- $tags[$arr[$i]] += 1;
- }
- else {
- $tags["$arr[$i]"] = 1;
- }
- }
- asort($tags);
- $sortedTags = array_reverse($tags);
- foreach ($sortedTags as $key => $value) {
- echo "$key: $value times <br>";
- }
- $val = array_search(max($sortedTags), $sortedTags);
- echo "Most frequent tag is $val";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment