🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #2905

Re: Ordenar arreglo multidimensional en PHP

#2905
From: Cristian Gutierrez
Date: Wed, 13 Jul 2005 23:54
35 lines
3040 bytes
Hoy en la tarde, jgarrido@dcc.uchile.NOSPAM.cl dijo:
>  Tengo un arreglo multidimensional de la forma

[...]

>   y quisiera ordenarlo segun NotaRamo o seg�n CodRamoEscuela. Buscando
> en la API de PHP, me top� con array_multisort, sin embargo aun no
> logro entender como usarlo para arreglos multidimensionales.
>
> Prob� con 
>
> array_multisort( $arreglo[]["NotaRamo"] ) pero no funcion�, ya que me
> alega que no puedo dejar los corchetes vacios y no encuentro alg�n
> comod�n para usar.
>
> Capaz que no se pueda usar esa funci�n para lo que quiero y tenga que
> implementarla a mano :-(

Yo usaria uasort() y una funcion de usuario:

funcion ordena_por_fechas ($a, $b) {
  return ($a['Nota'] > $b['Nota'] ? 1 : -1);
}

uasort($arreglo, 'ordea_por_fechas');

(obviamente no he probado nada :-P)

Al menos es la solucion estandar en Perl, donde `sort' siempre recibe
una funcion (anonima eso si) que sabe ordenar dos elementos cualquiera
del arreglo.

-- 
Cristian Gutierrez                          /* crgutier@dcc.uchile.cl */
WARNING: /dev/clue was linked to /dev/null
Technical Details
Message-ID: <873bqiuur6.fsf@guti.no-ip.org>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!guti.no-ip.org!news
References: <db41o4$pao$2@localhost.localdomain>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,d98161db675277b0
X-Google-Attributes: gid1593cb,public
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nntp-server.pubsub.com!news1.nivel5.cl!news.cec.uchile.cl!helcaraxe.dcc.uchile.cl!guti.no-ip.org!news
From: Cristian Gutierrez <crgutier@dcc.uchile.cl>
Newsgroups: chile.comp.programacion
Subject: Re: Ordenar arreglo multidimensional en PHP
Date: Wed, 13 Jul 2005 19:54:53 -0400
Organization: DCC - Universidad de Chile
Lines: 35
Message-ID: <873bqiuur6.fsf@guti.no-ip.org>
References: <db41o4$pao$2@localhost.localdomain>
NNTP-Posting-Host: anakena.dcc.uchile.cl
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: helcaraxe.dcc.uchile.cl 1121299277 12428 192.80.24.6 (14 Jul 2005 00:01:17 GMT)
X-Complaints-To: newsmaster@dcc.uchile.cl
NNTP-Posting-Date: Thu, 14 Jul 2005 00:01:17 +0000 (UTC)
Face: iVBORw0KGgoAAAANSUhEUgAAADwAAAA8AgMAAABHkjHhAAAADFBMVEUWFhZfX1+ioqL6+vr8
 dj+QAAAAAWJLR0QAiAUdSAAAAg5JREFUeNql0s9r02AYB/B4GIHuoAgVVmG9CVYwf4ILrht40Ynd
 dEXioWUsA3PaQQ8LKHpYLnbTThwiHbWYV9Sj9rL36NUObGkPUrVzuIs/6BvyluZ9ljcxaXI2lzwf
 eJOH9/k+AvhP/7j/Fv65OxMzmynhqO1zH/So+29NLeqvh6YU8WADmemIP4lxL8pxp6p3o2aZegZl
 R3YyaBJNaaGHKkqgxOXQNkKXzLQR+g9C6+b5kfcQevgmpYRuIrRZn5BCryO0US3ogW1BdV0J+3dz
 grpXmQXYfuf5nkLH5ksK/SIrnq/rg26ioTmdygtupwgWHSvoTnvF4CZl17dOYNoWy9yNPOzXfstg
 tYtXuR9o0JwlL+HgeWGBW8ZgGBbFnWUhw33Sbdz6TvHN1ey8a3YGIN+6T2C5PYFdD2sA6d5FAu9v
 LH3WBbAJBgmIDJ3ioooFoCzPNDq5in82TX7egsdXcE+0pZ3sEr+fxW7XoCvS3HRS4f7rrGHojRP0
 6A72TOtuoBrZnVvz5kGIzVejX0jpvi2bF0Q+iz1TWuXFwbOkP7/hrrdaH58u+HakX7wwSsF8/eDT
 wf45417kFwIPd7yIcWDS52UDApevuZ86p0PLK1tuZHpoBN8YLgOM9pswfft/vO9oMf9g6UbMYNij
 /jDYglZwHRCYIIgx56aO4earyPlD89R0Mvo/9kR9HfgIgorhXaQc58oAAAAASUVORK5CYII=
User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)
Cancel-Lock: sha1:dqvdJyHDxepMiAq2i1l99j9VOZY=