Let start,
Step 1:Create index.php file in xampp\htdocs\array\ folder and implement below code in it.
<!DOCTYPE html> <html> <head> <title>How To Store Single Input Array Data Through Loop In PHP</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> </head> <style> .bg_form{ background: lightblue; border-radius: 20px; padding: 10px; } </style> <body> <div class="container"> <div class="text-center"> <h1>How To Store Single Input Array Data Through Loop In PHP</h1> </div> <h2></h2> <form action="../demo/arrayfetch.php" method="post"> <div class="col-md-12 bg_form"> <div class="col-md-6"> <h4>Animals</h4> <input class="form-control" name="Animals[]"/><br> <input class="form-control" name="Animals[]"/><br> <input class="form-control" name="Animals[]"/><br> <input class="form-control" name="Animals[]"/><br> <input class="form-control" name="Animals[]"/><br> <input class="form-control" name="Animals[]"/><br> <input type="submit" value="save" class="btn btn-success"> </div> </div> </form> </div> <br> </body> </html>
<?php if(isset($_POST['Animals'])){ for($i = 0; $i<count($_POST['Animals']); $i++){ $pr_var = []; $pr_var['Animals'] = $_POST['Animals'][$i]; print_r($pr_var); // save your data in database } } ?>
http://localhost/array/index.php