Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

julioromano

ordenar array por um índice

Recommended Posts

tenho uma array do tipo:noticia[1][data]=24042006noticia[1][titulo]=titulonoticia[1][texto]=textonoticia[2][data]=24032006noticia[2][titulo]=titulonoticia[2][texto]=textonoticia[3][data]=21042006noticia[3][titulo]=titulonoticia[3][texto]=textocomo poderia fazer para ordenar essa array, em ordem decrescente do índice 'data' ?espero ter sido claro...gratojulio romano

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deve te ajudar

 

<pre>

<?php

 

$noticia[1]['data']=strtotime('2006-04-24');

$noticia[1]['titulo']='titulo';

$noticia[1]['texto']='texto';

 

$noticia[2]['data']=strtotime('2006-03-24');

$noticia[2]['titulo']='titulo';

$noticia[2]['texto']='texto';

 

$noticia[3]['data']=strtotime('2006-04-21');

$noticia[3]['titulo']='titulo';

$noticia[3]['texto']='texto';

 

array_multisort($noticia, SORT_ASC); // ($noticia, SORT_DESC)

 

print_r($noticia);

 

?>

</pre>

Observe que converti a data no padrão e para timestamp.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.