Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.Print Array
- <!DOCTYPE html>
- <html>
- <head>
- <title>Print Array</title>
- </head>
- <body>
- <?php
- $myArray = array(4, 2, 6, 1, 6, 4, 8, 34, 75, 1, 54, 2, 7, 9, 3, 16, 43, 86, 32, 5);
- foreach ($myArray as $key => &$value) {
- $value = $key*5;
- }
- echo '<pre>' . print_r($myArray, true) . '</pre>';
- ?>
- </body>
- </html>
- //2.Largest Sequence of Equal Strings
- <!DOCTYPE html>
- <html>
- <head>
- <title>Print Array</title>
- </head>
- <body>
- <form method="post">
- <input type="text" name="text">
- <input type="submit" value="Go">
- </form>
- <?php
- $myStr = $_POST['text'];
- $array = explode(" ", $myStr);
- $myArr = array_count_values($array);
- foreach ($myArr as $key => $value) {
- $value = max($myArr);
- $key = array_search($value, $myArr);
- }
- for ($i=1; $i <= max($myArr) ; $i++) {
- echo "$key ";
- }
- ?>
- </body>
- </html>
- //4.Selection Sort
- <!DOCTYPE html>
- <html>
- <head>
- <title>Selection Sort</title>
- </head>
- <body>
- <form method="post">
- <input type="text" name="text">
- <input type="submit" value="Go">
- </form>
- <?php
- $myStr = $_POST['text'];
- $array = explode(" ", $myStr);
- $buffer = "";
- echo '<pre>' . print_r($array, true) . '</pre>';
- for ($i = 0; $i < count($array) - 1; $i++) {
- for ($j = $i + 1; $j < count($array); $j++) {
- if ((int)$array[$i] > (int)$array[$j]) {
- $buffer = $array[$i];
- $array[$i] = $array[$j];
- $array[$j] = $buffer;
- }
- }
- }
- echo '<pre>' . print_r($array, true) . '</pre>';
- ?>
- </body>
- </html>
- //5.Simple Calculator
- <!DOCTYPE html>
- <html>
- <head>
- <title>Selection Sort</title>
- </head>
- <body>
- <form method="POST">
- <label for="first">Enter First Number</label>
- <input type="text" id="first" name="first">
- <br>
- <label for="operator">Select Operator</label>
- <select name="operator" id="operator">
- <option value="plus">+</option>
- <option value="minus">-</option>
- <option value="multiplication">*</option>
- <option value="divide">/</option>
- </select>
- <br>
- <label for="second">Enter Second Number</label>
- <input type="text" name="second" id="second">
- <br>
- <input type="submit" value="Calculate">
- </form>
- <?php
- $first = $_POST['first'];
- $second = $_POST['second'];
- $operator = $_POST['operator'];
- if ($operator == "plus") {
- $result = $first + $second;
- }
- if ($operator == "minus") {
- $result = $first - $second;
- }
- if ($operator == "multiplication") {
- $result = $first * $second;
- }
- if ($operator == "divide") {
- $result = $first / $second;
- }
- echo "Output = $result";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement