Anthony Gorshenin Anthony Gorshenin - 5 months ago 9
PHP Question

Array always re-create itself php

My programm read info from textbox and show it to user, so the problems is in middle part of that operation. How to make

$myArray
don't re-create itself when i update page?

session_start();

if (!isset($myArray)) $myArray = array();

$myArray[] = $_POST['nameAuthor'];

foreach($myArray as $key=>$value)
{
echo "$key->$value";
}

//$_SESSION['arr'] = $myArray;

Answer

Try this:

session_start();

if(!isset($_SESSION['arr'])) $_SESSION['arr'] =  array();

$_SESSION['arr'][] = $_POST['nameAuthor'];

foreach($_SESSION['arr'] as $key => $value)
{
    echo "$key->$value";    
}