0

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;

1 Answer 1

1

Try this:

session_start();

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

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

foreach($_SESSION['arr'] as $key => $value)
{
    echo "$key->$value";    
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answer, but it's throw: Parse error: syntax error, unexpected '[' in if(!isset($_SESSION['arr'])) $_SESSION['arr'] = [];
Your php version is < 5.4 ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.