I have a following array and i need to sort this array based upon the key value. I wrote a code and got perfect result if all numeric keys are different.
$myarray_need_to_sort =Array
(
[13] => 214
[14] => 215
[15] => 216
[21] => 223
)
Here is my code
$order = array();
foreach ($myarray_need_to_sort as $value){
$cat = Mage::getModel('catalog/category')->load($value);
$order[$cat->getTabOrder()] = $value;
}
ksort($order);
$sorted_order = array();
foreach ($order as $key=>$value)
{
$sorted_order[$key] = $value;
}
print_r($sorted_order);
$cat->getTabOrder() is the sort order i am getting from backend and result is perfect
Array
(
[1] => 216
[2] => 223
[3] => 215
[4] => 214
)
The code is sorting array perfectly but the issue is that if same key exists ie someone added $cat->getTabOrder() same say 2 and 2 for two values then it is removing one key. I need to add one increment for this like
Array
(
[1] => 216
[2] => 223
[2] => 215 -- it should be 3 and 4 should be 5 but it is removing 2 from here
[4] => 214 -- should be 5
)