Exemplo n.º 1
0
<?php

if (!isset($argv)) {
    exit('The script must be run from the command line');
}
print 'Please provide number values: ';
$values = fgets(STDIN);
function getDuplicates($input)
{
    $array = explode(' ', $input);
    if (!is_array($array)) {
        exit('Not an array.');
    }
    $values = array_count_values($array);
    $val = array_search(max($values), $values);
    return $val;
}
print 'The most frequent number is: ' . getDuplicates($values);
Exemplo n.º 2
0
<?php

require_once 'array_functions.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['frequent'])) {
        $input = $_POST['test'];
        $duplicates = getDuplicates($input);
    } elseif (isset($_POST['reverse'])) {
        $input = $_POST['test'];
        reverse($input);
    } elseif (isset($_POST['largest'])) {
        $input = $_POST['test'];
        echo largestArray($input);
    } elseif (isset($_POST['sort'])) {
        $input = $_POST['test'];
        $input = sortArray($input);
    }
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Array Test</title>
  </head>
  <body>
    <?php 
if (isset($duplicates)) {
    echo $duplicates;
}
?>