Renamed14789316
Anime Script Translator
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
In this tutorial we will create a Get the Even & Odd Number in an Array using PHP. This code can be use for storing of list of data. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding...
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server
.
And this is the link for the bootstrap that i used for the layout design
.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
Creating the Main Function
This code contains the main function of the application. This code will separate the even and odd numbers inside the array. To make this just simple copy and write the this block of codes inside the text editor, then save it as generate_number.php.
⚙ Live Demo
There you have it we successfully created Create Get the Even & Odd Number in an Array using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server
Loading…
www.apachefriends.org
And this is the link for the bootstrap that i used for the layout design
Loading…
getbootstrap.com
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Get the Even & Odd Number in an Array</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <form method="POST">
- <div class="form-inline">
- <label>Enter a number</label>
- <input type="number" class="form-control" max="100" name="number" required="required" min="1"/>
- <button name="generate">Generate Number</button>
- </div>
- </form>
- <br />
- <h4 class="text-info">Numbers</h4>
- <?php
- if
(
ISSET
(
$_POST
[
'generate'
]
)
)
{
- $array
=
[
]
;
- $number
=
$_POST
[
'number'
]
;
- for
(
$i
=
1
;
$i
<=
$number
;
$i
++
)
{
- array_push
(
$array
,
$i
)
;
- }
- echo
implode
(
", "
,
$array
)
;
- }
- ?>
- <br />
- <hr style="border-top:1px solid #ccc;"/>
- <?php
include
'generate_number.php'
?>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will separate the even and odd numbers inside the array. To make this just simple copy and write the this block of codes inside the text editor, then save it as generate_number.php.
- <?php
- if
(
ISSET
(
$_POST
[
'generate'
]
)
)
{
- $array
=
[
]
;
- $number
=
$_POST
[
'number'
]
;
- for
(
$i
=
1
;
$i
<=
$number
;
$i
++
)
{
- array_push
(
$array
,
$i
)
;
- if
(
$i
%
2
==
0
)
{
- $even
[
]
=
$i
;
- }
else
{
- $odd
[
]
=
$i
;
- }
- }
- ?>
- <div class="col-md-6">
- <h4 class="text-warning">EVEN</h4>
- <?php
- echo
implode
(
", "
,
$even
)
;
- ?>
- </div>
- <div class="col-md-6">
- <h4 class="text-warning">ODD</h4>
- <?php
- echo
implode
(
", "
,
$odd
)
;
- ?>
- </div>
- <?php
- }
- ?>
⚙ Live Demo
There you have it we successfully created Create Get the Even & Odd Number in an Array using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Download
You must upgrade your account or reply in the thread to view the hidden content.