Page 1 of 1

Need Help With Custom Array Sort

Posted: Sat Jun 18, 2005 11:38 am
by digitalnap
Hi. I am pulling my del.icio.us links via an RSS feed with MagpieRSS and got that working fine. The problem is I want to sort my links alphabetically on my website. I tried using sort() but it will only sort by post date then alphabetically so what I end up with is sections of alphabatized links as opposed to one long list. What I need to do is ignore the post date and sort solely by title. I am not familiar enough with PHP to figure out a way around this so I was wondering if someone on this board could provide me with some insight. Here is my code:

Code: Select all

<ul id="links">
          <?php
          
          require_once "../../magpierss/rss_fetch.inc";
          
          $yummy = fetch_rss("http://del.icio.us/rss/digitalnap/digitalnap");
          
          $maxitems = 5000;
          
          $yummyitems = array_slice($yummy->items, 0, $maxitems);
          
          sort($yummyitems);
          
          foreach ($yummyitems as $yummyitem) {
          
          print '<li>';
          print '<a href="';
          print $yummyitem['link'];
          print '" target="blank" title="';
          print $yummyitem['title'];
          print '">';
          print $yummyitem['title'];
          print '</a>';
          if (isset($yummyitem['description'])) {
          
          print '<br />';
          print '';
          print $yummyitem['description'];
          
          }
          print '</li>';
          print "\n";
          
          }
          
          ?>
          </ul>

Posted: Sat Jun 18, 2005 11:49 am
by hawleyjr
Put the following line of code before sort($yummyitems) and post what it says. So I can see what the array looks like now.


Code: Select all

echo '<HR><PRE>'; print_r($yummyitems); echo '</PRE>';

Posted: Sat Jun 18, 2005 11:55 am
by digitalnap

Code: Select all

Array
(
    &#1111;0] => Array
        (
            &#1111;about] => http://www.flickr.com/photos/990000/
            &#1111;title] => Flickr/Red
            &#1111;link] => http://www.flickr.com/photos/990000/
            &#1111;description] => Red's Flickr site
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-05-09T06:45:00Z
                    &#1111;subject] => digitalnap favorites friends nyc photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Red's Flickr site
            &#1111;date_timestamp] => 1115621100
        )

    &#1111;1] => Array
        (
            &#1111;about] => http://www2.foxsearchlight.com/gardenstate/blog/
            &#1111;title] => Zach Braff's Garden State Blog
            &#1111;link] => http://www2.foxsearchlight.com/gardenstate/blog/
            &#1111;description] => Weblog of Zach Braff (from Scrubs and Garden State)
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-05-08T16:27:00Z
                    &#1111;subject] => cinema digitalnap famous favorites weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Weblog of Zach Braff (from Scrubs and Garden State)
            &#1111;date_timestamp] => 1115569620
        )

    &#1111;2] => Array
        (
            &#1111;about] => http://hooplahngiggles.com/
            &#1111;title] => Hooplah and Giggles
            &#1111;link] => http://hooplahngiggles.com/
            &#1111;description] => Missouri based weblog
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-04-30T17:36:00Z
                    &#1111;subject] => digitalnap weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
  
            &#1111;topics] => 

            &#1111;summary] => Missouri based weblog
            &#1111;date_timestamp] => 1114882560
        )

    &#1111;3] => Array
        (
            &#1111;about] => http://wvs.topleftpixel.com/
            &#1111;title] => Daily Dose of Imagery
            &#1111;link] => http://wvs.topleftpixel.com/
            &#1111;description] => Photography by Toronto based Sam Javanrouh
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-04-30T03:47:00Z
                    &#1111;subject] => canada digitalnap photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Photography by Toronto based Sam Javanrouh
            &#1111;date_timestamp] => 1114832820
        )

    &#1111;4] => Array
        (
            &#1111;about] => http://www.frankieboots.net/
            &#1111;title] => Frankieboots
            &#1111;link] => http://www.frankieboots.net/
            &#1111;description] => Photography of NYC based Michael Dominic
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-04-30T02:11:00Z
                    &#1111;subject] => digitalnap nyc photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Photography of NYC based Michael Dominic
            &#1111;date_timestamp] => 1114827060
        )

    &#1111;5] => Array
        (
            &#1111;about] => http://alistapart.com/
            &#1111;title] => A List Apart
            &#1111;link] => http://alistapart.com/
            &#1111;description] => For people who make websites
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-04-25T07:45:00Z
                    &#1111;subject] => design digitalnap digitalnap_design favorites resources web_design_resources web_standards
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => For people who make websites
            &#1111;date_timestamp] => 1114415100
        )

    &#1111;6] => Array
        (
            &#1111;about] => http://positive-negative.com/
            &#1111;title] => Positive Negative
            &#1111;link] => http://positive-negative.com/
            &#1111;description] => Photography of NYC based Frank Kolodziej
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-04-25T07:19:00Z
                    &#1111;subject] => digitalnap favorites nyc photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Photography of NYC based Frank Kolodziej
            &#1111;date_timestamp] => 1114413540
        )

    &#1111;7] => Array
        (
            &#1111;about] => http://stopdesign.com/
            &#1111;title] => Stopdesign
            &#1111;link] => http://stopdesign.com/
            &#1111;description] => Design consultancy based in San Francisco, CA
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-04-25T07:13:00Z
                    &#1111;subject] => design digitalnap favorites s web_design_resources web_standards weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Design consultancy based in San Francisco, CA
            &#1111;date_timestamp] => 1114413180
        )

    &#1111;8] => Array
        (
            &#1111;about] => http://www.kottke.org/
            &#1111;title] => Kottke
            &#1111;link] => http://www.kottke.org/
            &#1111;description] => Home of fine hypertext products
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-07T21:05:00Z
                    &#1111;subject] => digitalnap favorites nyc weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Home of fine hypertext products
            &#1111;date_timestamp] => 1105131900
        )

    &#1111;9] => Array
        (
            &#1111;about] => http://www.990000.com/
            &#1111;title] => 990000
            &#1111;link] => http://www.990000.com/
            &#1111;description] => New Yory City photography
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T22:15:00Z
                    &#1111;subject] => digitalnap favorites friends nyc photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => New Yory City photography
            &#1111;date_timestamp] => 1104963300
        )

    &#1111;10] => Array
        (
            &#1111;about] => http://chicagouncommon.com/
            &#1111;title] => Chicago Uncommon
            &#1111;link] => http://chicagouncommon.com/
            &#1111;description] => Chicago Photos, Photographs, Pictures by Dawn Mikulich
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T22:06:00Z
                    &#1111;subject] => chicago digitalnap favorites photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Chicago Photos, Photographs, Pictures by Dawn Mikulich
            &#1111;date_timestamp] => 1104962760
        )

    &#1111;11] => Array
        (
            &#1111;about] => http://www.absenter.org/
            &#1111;title] => Absenter
            &#1111;link] => http://www.absenter.org/
            &#1111;description] => Photographs, images, visuals from Chicago
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T22:06:00Z
                    &#1111;subject] => chicago digitalnap favorites photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Photographs, images, visuals from Chicago
            &#1111;date_timestamp] => 1104962760
        )

    &#1111;12] => Array
        (
            &#1111;about] => http://www.toybird.org/
            &#1111;title] => Toybird
            &#1111;link] => http://www.toybird.org/
            &#1111;description] => Weblog of Chicago based Nazarin Hamid
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T22:02:00Z
                    &#1111;subject] => chicago digitalnap favorites weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Weblog of Chicago based Nazarin Hamid
            &#1111;date_timestamp] => 1104962520
        )

    &#1111;13] => Array
        (
            &#1111;about] => http://simplebits.com/
            &#1111;title] => SimpleBits
            &#1111;link] => http://simplebits.com/
            &#1111;description] => Hand-crafted web sites, pixels and text
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T20:57:00Z
                    &#1111;subject] => design digitalnap favorites s web_design_resources web_standards weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Hand-crafted web sites, pixels and text
            &#1111;date_timestamp] => 1104958620
        )

    &#1111;14] => Array
        (
            &#1111;about] => http://subinev.com/
            &#1111;title] => Subinev
            &#1111;link] => http://subinev.com/
            &#1111;description] => Bryan's words and photos and whatever else he feels the need to spew onto the internet.
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T20:54:00Z
                    &#1111;subject] => digitalnap favorites friends nyc photoblogs photography s weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Bryan's words and photos and whatever else he feels the need to spew onto the internet.
            &#1111;date_timestamp] => 1104958440
        )

    &#1111;15] => Array
        (
            &#1111;about] => http://rion.nu/
            &#1111;title] => Rion
            &#1111;link] => http://rion.nu/
            &#1111;description] => New York City street photography by Rion Nakaya
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T20:54:00Z
                    &#1111;subject] => digitalnap favorites friends nyc photoblogs photography
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => New York City street photography by Rion Nakaya
            &#1111;date_timestamp] => 1104958440
        )

    &#1111;16] => Array
        (
            &#1111;about] => http://www.spreadfirefox.com/
            &#1111;title] => Spread Firefox
            &#1111;link] => http://www.spreadfirefox.com/
            &#1111;description] => Community site devoted to spreading the word about Firefox
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T20:47:00Z
                    &#1111;subject] => communities digitalnap firefox s
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Community site devoted to spreading the word about Firefox
            &#1111;date_timestamp] => 1104958020
        )

    &#1111;17] => Array
        (
            &#1111;about] => http://engadget.com/
            &#1111;title] => Engadget
            &#1111;link] => http://engadget.com/
            &#1111;description] => Web magazine about the world of gadgets and consumer electronics
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T19:04:00Z
                    &#1111;subject] => digitalnap favorites technology weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Web magazine about the world of gadgets and consumer electronics
            &#1111;date_timestamp] => 1104951840
        )

    &#1111;18] => Array
        (
            &#1111;about] => http://yewknee.com/
            &#1111;title] => Yewknee
            &#1111;link] => http://yewknee.com/
            &#1111;description] => Weblog of Michael Eades
            &#1111;dc] => Array
                (
                    &#1111;creator] => digitalnap
                    &#1111;date] => 2005-01-05T18:12:00Z
                    &#1111;subject] => digitalnap favorites weblogs
                )

            &#1111;taxo] => Array
                (
                    &#1111;topics] => 
  
                    &#1111;topics_bag] => 
    
                )

            &#1111;topics_bag] => 
    
    
  
            &#1111;topics] => 

            &#1111;summary] => Weblog of Michael Eades
            &#1111;date_timestamp] => 1104948720
        )

)

Posted: Sat Jun 18, 2005 11:58 am
by hawleyjr
Use array_multisort()

There are examples on the link below:

http://us2.php.net/manual/en/function.a ... tisort.php

Posted: Sat Jun 18, 2005 12:16 pm
by digitalnap
I tried working with array_multisort but could not get anything to work. Can someone please help with implementing this? Thanks!

Posted: Sat Jun 18, 2005 12:18 pm
by hawleyjr
No problem. Post what you've tried and we'll work through it.

Posted: Sat Jun 18, 2005 12:21 pm
by digitalnap
Actually, I just got it!

This is what I used:

Code: Select all

function comparar($a, $b) {
  return strnatcasecmp($a["title"], $b["title"]);
}

usort($yummyitems, "comparar");


Thanks for the help!