note 73525 deleted from function.array-multisort by cmb
| From: | cmb@php.net | Date: | Sun, 29 Sep 2019 07:46:01 +0000 |
| Subject: | note 73525 deleted from function.array-multisort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212418@lists.php.net to get a copy of this message | ||
Note Submitter: vermon7
----
When using array_multisort() on copies of arrays, it is changing all the copies, even if you modify
the copy before using array_multisort().
I've avoided this bug by serializing a copy of array before calling array_multisort, and
unserializg it after array_multisort() Look at the code:
<?php
$records_copy = serialize($records) ;
array_multisort ( $records[$sort_field] , $records[$sort2_field] ) ;
$records_copy = unserialize($records_copy) ;
?>