Skip to content

Commit b961bd9

Browse files
committed
Initial commit
0 parents  commit b961bd9

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Alain Pascal
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# About php_arrayGenerator
3+
4+
php_arrayGenerator is a php program that generates a size defined array of random elements.
5+
6+
## Installation
7+
8+
1. Ensure a local server like [WampServer](https://www.wampserver.com/en/) or [XAMPP](hhttps://www.apachefriends.org/download.html) or [MAMP](https://www.mamp.info/en/downloads/) or the LAMP stack is installed and running
9+
10+
2. Download and install the [Git](https://git-scm.com/downloads) version control system
11+
12+
3. Install a text editor or IDE like [Sublime Text](https://www.sublimetext.com/) or [Atom](https://atom.io/) or [Visual Studio Code](https://code.visualstudio.com/)
13+
14+
4. Install a web browser like [Google Chrome](https://www.google.com/chrome/) or [Firefox](https://www.mozilla.org/en-US/firefox/)
15+
16+
5. Clone the GitHub Repository php_arrayGenerator to local host
17+
```
18+
$ git clone https://github.com/AlainPascal/php_arrayGenerator.git
19+
20+
$ cd php_arrayGenerator
21+
```
22+
6. Open browser and enter the following URL `localhost/php_arrayGenerator/index.php`
23+
24+
25+
### _To Do_
26+
27+
1. Add code to generate array of random strings
28+
2. Add code to generate unique array elements
29+
30+
## Contributing
31+
32+
Contributions to php_arrayGenerator are encouraged. Kindly refer to the To Do list and push the changes
33+
34+
## License
35+
36+
php_arrayGenerator is licensed under the [MIT License](https://github.com/AlainPascal/php_arrayGenerator/blob/master/LICENSE).

index.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<style>
8+
.error {color: #FF0000;}
9+
</style>
10+
<title>Array Generator</title>
11+
</head>
12+
<body>
13+
<?php
14+
// define variables and set to empty values
15+
$sizeError = "";
16+
$arraySize = 0;
17+
$generated = false;
18+
19+
// do the following when the button is clicked
20+
if(isset($_POST['btnGenerate'])){
21+
// set input from form to variable
22+
$arraySize = $_POST['array_size'];
23+
24+
// check whether input variable is empty or not numeric
25+
if(is_numeric($arraySize) == false || empty($arraySize)){
26+
$sizeError = "Invalid array size";
27+
}else{
28+
// define the array of random numbers based on the given size
29+
$arrayOfInt = array();
30+
for($i = 0; $i < $arraySize; $i++){
31+
$arrayOfInt[$i] = mt_rand(10, 100);
32+
}
33+
34+
$generated = true;
35+
}
36+
}
37+
?>
38+
39+
<form method="POST">
40+
<table>
41+
<tr>
42+
<td><label for="array_size">Enter size of array:</label></td>
43+
<td>
44+
<input type="text" name="array_size">
45+
<span class="error">* <?php echo $sizeError; ?></span>
46+
</td>
47+
</tr>
48+
<tr>
49+
<td><button type="submit" name="btnGenerate">Generate</button></td>
50+
</tr>
51+
</table>
52+
</form>
53+
54+
<?php
55+
if($generated == true){
56+
// display array elements separated by commas
57+
$arrayElements = implode(', ', $arrayOfInt);
58+
echo "<br><br>Generated Array = [" . $arrayElements . "]";
59+
60+
echo "<br><br> Size of generated array is ". $arraySize. "<br>";
61+
}
62+
?>
63+
</body>
64+
</html>

0 commit comments

Comments
 (0)