note 28068 modified in function.usort by thiago

From: Date: Tue, 22 Jul 2008 19:17:49 +0000
Subject: note 28068 modified in function.usort by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142569@lists.php.net to get a copy of this message
The sort functions do nothing if identical keys exist. Of course, you shouldn't have identical keys anyway, but this just might save someone else the oodles of time it took me to figure out while using multi-dimentional arrays: <?php class myArticleList { // ... // function &getList () { // works $a = array ( "articleList1" => array ( "2", "3" ), "articleList2" => array ( "3" , "4") ); usort( $a, array( $this, "compareByTitle") ); // doesn't work $b = array ( "articleList" => array ( "2", "3" ), "articleList" => array ( "3" , "4") ); usort( $b, array( $this, "compareByTitle") ); } function compareByTitle( $a, $b ) { // ... // } } ?> --was-- The sort functions do nothing if identical keys exist. Of course, you shouldn't have identical keys anyway, but this just might save someone else the oodles of time it took me to figure out while using multi-dimentional arrays: class myArticleList { // ... // function &getList () { // works $a = array ( "articleList1" => array ( "2", "3" ), "articleList2" => array ( "3" , "4") ); usort( $a, array( $this, "compareByTitle") ); // doesn't work $b = array ( "articleList" => array ( "2", "3" ), "articleList" => array ( "3" , "4") ); usort( $b, array( $this, "compareByTitle") ); } function compareByTitle( $a, $b ) { // ... // } } http://php.net/manual/en/function.usort.php

« previous php.notes (#142569) next »