note 38957 modified in function.array-multisort by vrana

From: Date: Tue, 17 Aug 2004 13:59:04 +0000
Subject: note 38957 modified in function.array-multisort by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79993@lists.php.net to get a copy of this message
I needed a function to sort multi dimensional arrays, but case in-sensitive. I used Ichier function with a little modification: <?php function array_csort() { //coded by Ichier2003 $args = func_get_args(); $marray = array_shift($args); $msortline = "return(array_multisort("; foreach ($args as $arg) { $i++; if (is_string($arg)) { foreach ($marray as $row) { // added by Marin for case in-sensitive search $a = strtoupper($row[$arg]); $sortarr[$i][] = $a; } } else { $sortarr[$i] = $arg; } $msortline .= "\$sortarr[".$i."],"; } $msortline .= "\$marray));"; eval($msortline); return $marray; } ?> For usage of this function, see Ichier's post somewhere below Thanks Ichier, a superb function indeed! --was-- I needed a function to sort multi dimensional arrays, but case in-sensitive. I used Ichier function with a little modification: function array_csort() { //coded by Ichier2003 $args = func_get_args(); $marray = array_shift($args); $msortline = "return(array_multisort("; foreach ($args as $arg) { $i++; if (is_string($arg)) { foreach ($marray as $row) { // added by Marin for case in-sensitive search $a = strtoupper($row[$arg]); $sortarr[$i][] = $a; } } else { $sortarr[$i] = $arg; } $msortline .= "\$sortarr[".$i."],"; } $msortline .= "\$marray));"; eval($msortline); return $marray; } For usage of this function, see Ichier's post somewhere below Thanks Ichier, a superb function indeed! http://php.net/manual/en/function.array-multisort.php

« previous php.notes (#79993) next »