Jump to content

Sorting an array in PHP.


sepoto

Recommended Posts

	  foreach ($articles as $article)	  {		  $title	   = str_replace('DSG_Steve:', '', $article['title']);		  $description = str_replace('DSG_Steve:', '', $article['description']);		  $lines = explode("\n",wordwrap($title,60));		  $title = $lines[0];		  echo "{$title}... <a class='feed' href='{$article['link']}' target='_new'>More ></a><br/><br/>";	  }

I'm looking for the least amount of code that will sort my array $articles by $article['date']; Does anyone know how to do that?Thank you!

Link to comment
Share on other sites

Aye aye, take a look at the ksort function which sorts an array by the key. If that doesn't do it, PHP has a bunch of sorting functions for sorting arrays. http://uk.php.net/manual/en/function.ksort.phpHope that's what your looking for.

Link to comment
Share on other sites

If you are getting the articles from a database you could also sort the results when querying.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...