Push items to PHP array using a form
one text
Solution:
I tried to implement the same using sessions, that works fine for me,
if (isset($_POST['insertProduct'])) {
$inserted_code = $_POST['code'];
$inserted_products = array("Entry 1", "Entry 2");
if (isset($_SESSION['myArray'])) {
$inserted_products = $_SESSION['myArray'];
array_push($inserted_products, "Entry $inserted_code");
$_SESSION['myArray'] = $inserted_products;
} else {
array_push($inserted_products, "Entry $inserted_code");
$_SESSION['myArray'] = $inserted_products;
}
}
Source