After sorting an array using a sorting function (sort, rsort, asort etc), I want to reset the array back so that its values are located at their original index numbers. What command is there if any which achieve this?

    dalecosp;10941849 wrote:

    I believe you want [man]reset/man.

    Correct me if I'm wrong but dalecosp but I thought reset only allowed you to reset to the first element in an array. Despite the fact that the title matches with that function, I'm looking to reset different sort functions, like sort, rsort or asort.

      There's no "command" that can do this. If you tell PHP to modify an array, and store the newly modified array in the same variable that held the old array, then it will do just that - it won't save the old version of the array so you can revert back to it.

      If you really have a need to keep the unsorted array as well as the sorted one, just store the two arrays in different variables instead of overwriting the original.

        Thanks bradgrafelman. I guess that means $array1 and $array2 it will be.

          Write a Reply...