note 126198 added to function.usort

From: Date: Fri, 25 Jun 2021 15:01:21 +0000
Subject: note 126198 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-216551@lists.php.net to get a copy of this message
The usort function should not be used for associative arrays where the base keys need to retain their names, otherwise this: $a = array('example' => 'hello'); Will be converted to: $a = array(0 => 'hello'); To retain key names in associative arrays you can simply replace usort with uasort; for me it was a drop-in replacement without having to change anything else. ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 154.21.22.183) ---- Manual Page -- https://php.net/manual/en/function.usort.php Edit -- https://main.php.net/note/edit/126198 Del: integrated -- https://main.php.net/note/delete/126198/integrated Del: useless -- https://main.php.net/note/delete/126198/useless Del: bad code -- https://main.php.net/note/delete/126198/bad+code Del: spam -- https://main.php.net/note/delete/126198/spam Del: non-english -- https://main.php.net/note/delete/126198/non-english Del: in docs -- https://main.php.net/note/delete/126198/in+docs Del: other reasons-- https://main.php.net/note/delete/126198 Reject -- https://main.php.net/note/reject/126198 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216551) next »