1

I want to have a numerical, multidimensional array of scores. The first index is the page load, and the second is the score value for the particular question. When I push to the array, the load value is already defined.

I keep getting this error: Warning: array_push() expects parameter 1 to be array, null given in (...)

I'm guessing there's an issue with how I declared the array in the first place, but I've also tried array() and array()array() and neither of those worked. My search skills are failing me, and I'm out of ideas. Here's the relevant code:

if (!isset($_SESSION['scores'])) {
    $_SESSION['scores'] = array(array());
}

if ($users[$i] == $useSet[$i+2]) {
    array_push($_SESSION['scores'][$_SESSION['load']], 'c');
}

1 Answer 1

2

Try using square bracket syntax instead:

$_SESSION['scores'][$_SESSION['load']][] = 'c';
Sign up to request clarification or add additional context in comments.

Comments

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.