I have a multi-dimensional array (stored in a cookie) containing the sort values for different categories:
Array
(
[category1] => Array
(
[order] => count
[sort] => desc
)
[category2] => Array
(
[order] => title
[sort] => asc
)
[category3] => Array
(
[order] => count
[sort] => asc
)
)
Now i'm retrieving these values from the cookie:
$order = unserialize(stripslashes($_COOKIE['order']));
if (array_key_exists($category, $order)) {
$sort = $order[$category]['sort'];
$order = $order[$category]['order'];
} else {
$order = $default_order;
$sort = "asc";
}
Works like a charm, no problems but here comes the question: if i swap the last two lines:
$order = $order[$category]['order'];
$sort = $order[$category]['sort'];
$sort variable is no longer available. 🙁
Being a curious person, i want to know why it's happening. I may have done something wrong in the code (i'm a beginner) but it wouldn't have worked then so any explanation is highly appreciated.