From:             
Operating system: OS X 10.6
PHP version:      5.3.5
Package:          Arrays related
Bug Type:         Feature/Change Request
Bug description:Add SORT_NONE type to array_mulitsort

Description:
------------
It'd be useful to have a SORT_NONE option in the array_multisort function. 
This 

would allow users to specify that they do not care to sort along a
particular 

index.



In the sample code below, I've attached one possible use arising in Drupal.
(See 

http://drupal.org/node/972536).  Generically, we want to sort some array
($menu) 

before inserting it into the database.  To do so, we first compute the
desired 

sort order ($sort) and then call the array_multisort function as

  array_multisort($sort, SORT_NUMERIC, $menu);



This works great, sorting $menu according to the sort order in $sort,
however if 

$menu contains any objects the array_multisort function throws an error
(Notice: 

Object of class stdClass could not be converted to int in ...).



I'm proposing the addition of a SORT_NONE option so that the function call
could 

instead be

  array_multisort($sort, SORT_NUMERIC, $menu, SORT_NONE);

This would not throw an error since no comparisons would be done with the 

attributes of $menu.



Implementing this should be relatively straightforward, I would imagine.

Test script:
---------------
$sort = array(

  'A' => 2,

  'A' => 1,

  'B' => 1,

);

$menu['A'] = array(

  'access' => array(1),

);

$menu['B'] = array(

  'access' => array((object) array('a', 'b')),

);

$menu['C'] = array(

  'access' => array(0),

);



array_multisort($sort, SORT_NUMERIC, $menu, SORT_NONE);



Expected result:
----------------
$sort =

Array

(

    [C] => 1

    [B] => 1

    [A] => 2

)



$menu =

Array

(

    [C] => Array

        (

            [access] => Array

                (

                    [0] => 0

                )



        )



    [B] => Array

        (

            [access] => Array

                (

                    [0] => stdClass Object

                        (

                            [0] => a

                            [1] => b

                        )



                )



        )



    [A] => Array

        (

            [access] => Array

                (

                    [0] => 1

                )



        )



)



Actual result:
--------------
(Not applicable, since this is a feature request).

-- 
Edit bug report at http://bugs.php.net/bug.php?id=54259&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54259&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54259&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54259&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54259&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54259&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54259&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54259&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54259&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54259&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54259&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54259&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54259&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54259&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54259&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54259&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54259&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54259&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54259&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54259&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54259&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54259&r=mysqlcfg

Reply via email to