Eg:
$_SESSION['1'] = 'username'; // works
$_SESSION[1] = 'username'; //doesnt work
I want to store session array index as array index. So that o/p is :
Array(
[1] => 'username'
)
Eg:
$_SESSION['1'] = 'username'; // works
$_SESSION[1] = 'username'; //doesnt work
I want to store session array index as array index. So that o/p is :
Array(
[1] => 'username'
)
$_SESSION
can only be used as an associative array.
You could do something like this though:
$_SESSION['normal_array'] = array();
$_SESSION['normal_array'][0] = 'index 0';
$_SESSION['normal_array'][1] = 'index 1';
Personally, I'd just stick with the associative array.
$_SESSION['username'] = 'someuser';
Or
$_SESSION['username_id'] = 23;
I suspect this is probably because the $_SESSION array is purely an associative array. Additionally, as the PHP manual puts it:
The keys in the $_SESSION associative array are subject to the same limitations as regular variable names in PHP, i.e. they cannot start with a number and must start with a letter or underscore.
Incidentally, have you checked your error log for any NOTICE level errors? (You may have to enable this level.) Attempting to use a numeric key will quite possibly raise an error.
You can also take this approach to save an array dimension:
$_SESSION['form_'.$form_id] = $form_name;
which might look like the following:
$_SESSION['form_21'] = 'Patient Evaluation';
as opposed to:
$_SESSION['form'][21] = 'Patient Evaluation';
which uses another array dimension.