Sorry to ask if it was already asked before, but none of those solutions worked for me. Everytime I try to add into array, what I get is new array. See PHP code below:
<?php
session_start();
if (!isset($_SESSION['$rNumber'])){
$_SESSION['$rNumber'] = 0;
}
if(empty($_SESSION['words']))
{
$_SESSION['words'] = array();
}
if (isset($_POST['button1'])){
$random = rand(10, 20);
$_SESSION['$rNumber'] = $_SESSION['$rNumber'] + $random;
$word = 'You entered a farm and earned '.$random.' golds.';
array_push($_SESSION['words'], $word);
} else if ...
}
?>
When I var_dump the $words[], it always has 1 value only, though I add this very many times! Please let me know if additional info needed. Thanks!
'$rNumber'is going to put an entry in your array where the key is the literal characters$,r,N, etc...[]is the push operator, and as written you'd be pushing nothing because it has to be$arr[] = $something.$_SESSION['words'][]to have more than one entry? No loop, so I am guessing you want it to add a new element to the array each time something is Posted?$_SESSION['$rNumber'] += $random;- not addressing your issue, but makes life a bit nicer.