禁用$ _SESSION数组内的排序

I have a session variable which looks like this when printed:

Array
(
    [cart_4] => 1
    [cart_8] => 1
    [cart_9] => 2
    [cart_18] => 1
)

The thing is, i did not add stuff to it in that order, but because of the keys it always has that order. So is it possible to keep the items inside the session array the way they were added, not like this?

In this particular example, I added cart_8 last, and as you can see it is second in the list.

You must be splicing elements in or sorting the array. The order of an array is the order in which the elements were were added:

$a['cart_9'] = 2;
$a['cart_18'] = 1;
$a['cart_4'] = 1;
$a['cart_8'] = 1;

print_r($a);

Array
(
    [cart_9] => 2
    [cart_18] => 1
    [cart_4] => 1
    [cart_8] => 1
)

Even for numerically indexed arrays:

$a[9] = 2;
$a[18] = 1;
$a[4] = 1;
$a[8] = 1;

print_r($a);

Array
(
    [9] => 2
    [18] => 1
    [4] => 1
    [8] => 1
)