<?php if (!isset($argv)) { exit('The script must be run from the command line'); } print 'Please provide an array of numbers: '; $values = fgets(STDIN); function largestArray($array) { $integer = array_map('floatval', explode(', ', $array)); $onlyInt = array_filter($integer, 'is_numeric'); foreach ($onlyInt as $key => $value) { if ($value == 0) { exit('Array must only be integer or float.'); } } $value = max($onlyInt); return $value; } echo 'The largest value on the array is: ' . largestArray($values);
<?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; } ?>