SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ordering json decode content

    I have a calendar type setup where the events are stored within a single database field as json data (sample below). My problem is if they don't enter them in the right time order they come out in the the order they have been entered. The below sample shows this with the event at 13:15 before the 08:45 event.

    How do I go about ordering this by the time slots in the data?


    SAMPLE DATA - NOTE THIS IS TWO RECORDS
    Code:
    ["13:15 to 14:15: NCC SWL Induction","08:45 to 12:00: Meet with Jane re: PPP Course"]
    Currently the calling code is:

    PHP Code:
    <?php $items=json_decode($timetable['Timetable']['timetable_wed']);
                            if(
    count($items)>0){
                        
    $key=0;
                        foreach(
    $items as $item){
                        
    $key++;
                                echo 
    $item."</br>";
                            }
                        }
    ?>

    Thankyou

  2. #2
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found the answer: sort($items);

    PHP Code:
    <?php $items=json_decode($timetable['Timetable']['timetable_wed']);
                            if(
    count($items)>0){
                        
    $key=0;
                        
    sort($items);
                        foreach(
    $items as $item){
                        
    $key++;
                                echo 
    $item."</br>";
                            }
                        }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •