PHP bug in array_multisort()
This is a php bug post, so if you don't use php, stop reading now.
Be careful when using array_multisort() on copies of arrays, as you might end up changing the original array. I lost half a day to debugging as a result of this. Given the following code:
You would expect:
However, if you run the code, you actually get:
Note that the original ($test1) ends up being sorted even though it was never called by array_multisort(). To work around this, insert a statement to modify the copy ($test2) before calling array_multisort() on it. The following code will produce the expected "correct" results:
This seems to be a resurrection of the closed bug #8130. Also, someone reported this behavior in bug #32031, but it was incorrectly labeled "bogus" in reference to bug #25359, which is a different issue. This was tested on PHP 5.0.4-dev.