I insert data to the array from an input box. But I don't know why I can't print the associative array. I can only echo the latest data from the input box. I want to add data to the array and echo it every time I write to the input box.
<?php
$part_insert_message = "";
$inserted_parts = array();
session_start();
$part_inserted_id;
if(isset($_POST['submit'])) {
$part_inserted_id = $_POST['arrdata'];
$inserted_parts[$part_inserted_id] = $part_inserted_id;
echo sizeof($inserted_parts);
// store session data
$_SESSION['views']= $inserted_parts;
$part_insert_message = "ID: " . $part_inserted_id;
}
?>
<html>
<body>
<div>
<h2>Part</h2>
<form action="array_session_example.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
Array Data: <input type="text" name="arrdata"><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php echo $part_insert_message;
foreach($inserted_parts as $key => $value){
echo $key;
}
?>
</div>
</body>
</html>