-1

Here is my current output for an array:

array(7) {
  [4]=>
  array(4) {
    ["opentime"]=>
    float(6)
    ["openspec"]=>
    string(2) "PM"
    ["closetime"]=>
    float(12)
    ["closespec"]=>
    string(2) "AM"
  }
  [5]=>
  array(4) {
    ["opentime"]=>
    float(6)
    ["openspec"]=>
    string(2) "PM"
    ["closetime"]=>
    float(12)
    ["closespec"]=>
    string(2) "AM"
  }
  [0]=>
  array(0) {
  }
  [1]=>
  array(0) {
  }
  [2]=>
  array(0) {
  }
  [3]=>
  array(0) {
  }
  [6]=>
  array(0) {
  }
}

As you can see the array starts at position 4 and then moves to 5, followed by 0,1,2,3,6.

I need to preserve the keys but reorganize them so they start at 0 and move towards 6

Not quite sure how to do this. It seems fairly trivial.

Thanks.

somejkuser
  • 8,856
  • 20
  • 64
  • 130

1 Answers1

3

You can use ksort :

http://php.net/manual/en/function.ksort.php

Sorts an array by key, maintaining key to data correlations.

ksort($myArray);
var_dump($myArray);
jiboulex
  • 2,963
  • 2
  • 18
  • 28