note 94883 modified in function.uasort by danbrown

From: Date: Tue, 01 Dec 2009 16:13:28 +0000
Subject: note 94883 modified in function.uasort by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163451@lists.php.net to get a copy of this message
Just expanding on php arobase kochira period com's method: If you are looking to sort a multi-D array by a specific column and have entries in both upper and lower case, simply drop the entries to lowercase before doing the strcmp. <?php $dirs = array( array('name' => 'First Folder', 'path' => 'sompath'), array('name' => 'second folder', 'path' => 'sompath2'), array('name' => 'Third Folder', 'path' => 'sompath3') ); function so($a, $b) { return (strcmp (strtolower($a['name']), strtolower($b['name']))); } ?> --was-- Just expanding on php arobase kochira period com's method: If you are looking to sort a multi-D array by a specific column and have entries in both upper and lower case, simply drop the entries to lowercase before doing the strcmp. $dirs = array( array('name' => 'First Folder', 'path' => 'sompath'), array('name' => 'second folder', 'path' => 'sompath2'), array('name' => 'Third Folder', 'path' => 'sompath3') ); function so($a, $b) { return (strcmp (strtolower($a['name']), strtolower($b['name']))); } http://php.net/manual/en/function.uasort.php

« previous php.notes (#163451) next »