Tried examples from 'php.net' but don't understand what's the problem. Any suggestions?
<?php
$_SESSION['test'] = array('a' 开发者_开发问答=> '1', 'b' => '2');
foreach ($_SESSION['test'] as $key => $val)
echo "key: " . $key . " val: " . $val . "\n";
// Parse error
array_push($_SESSION['test']['c'] => '3');
// Parse error
$_SESSION['test'][] = ('c' => '3');
foreach ($_SESSION['test'] as $key => $val)
echo "key: " . $key . " val: " . $val . "\n";
?>
Is this what you are looking for?
$_SESSION['test']['c'] = '3';
[]
is designed to append to a numeric-key array. If you used this on an associative array, it will result in an index of (largest numeric-key + 1).
精彩评论