Hi, so im pulling arrays from facebook. But i would like to sort them.

Here is how the arrays look

Array

(

    [0] => Array

        (

            [eid] => 203966119376

            [name] => Funtastic -  a show for the whole family!

            [tagline] => 

            [nid] => 0

            [pic] => http://profile.ak.fbcdn.net/object2/857/53/s203966119376_6012.jpg

            [pic_big] => http://profile.ak.fbcdn.net/object2/857/53/n203966119376_6012.jpg

            [pic_small] => http://profile.ak.fbcdn.net/object2/857/53/t203966119376_6012.jpg

            [host] => Silverstar Casino

            [description] => Dates: 16 December 2009 – 7 March 2010 

(Thurs – Sunday)

Times: Thurs, Fri and Sat at 8pm and Sundays at 3pm.

Book through Computicket



RSVP attending this event and stand a chance to win 2 tickets to the Funtastic Show.

            [event_type] => Music/Arts

            [event_subtype] => Performance

            [start_time] => 1261022400

            [end_time] => 1268020800

            [creator] => 138907126863

            [update_time] => 1256047911

            [location] => Silverstar Centre

            [venue] => Array

                (

                    [street] => 

                    [city] => 

                    [state] => 

                    [country] => 

                )



            [privacy] => OPEN

            [hide_guest_list] => 0

            [show_in_search] => 0

        )



    [1] => Array

        (

            [eid] => 173559209746

            [name] => Comedy Night with Joey Rasdien

            [tagline] => 

            [nid] => 0

            [pic] => http://profile.ak.fbcdn.net/object2/1109/94/s173559209746_2253.jpg

            [pic_big] => http://profile.ak.fbcdn.net/object2/1109/94/n173559209746_2253.jpg

            [pic_small] => http://profile.ak.fbcdn.net/object2/1109/94/t173559209746_2253.jpg

            [host] => Silverstar Casino

            [description] => RSVP attending this event and stand a chance to win 2 tickets to the Comedy Night with Joey Rasdien at Silverstar Centre.

            [event_type] => Music/Arts

            [event_subtype] => Performance

            [start_time] => 1256958000

            [end_time] => 1256961600

            [creator] => 138907126863

            [update_time] => 1255943074

            [location] => Silverstar Centre

            [venue] => Array

                (

                    [street] => 

                    [city] => 

                    [state] => 

                    [country] => 

                )



            [privacy] => OPEN

            [hide_guest_list] => 0

            [show_in_search] => 0

        )



    [2] => Array

        (

            [eid] => 141255783702

            [name] => Steve Hofmeyr

            [tagline] => 

            [nid] => 0

            [pic] => http://profile.ak.fbcdn.net/object2/575/107/s141255783702_3620.jpg

            [pic_big] => http://profile.ak.fbcdn.net/object2/575/107/n141255783702_3620.jpg

            [pic_small] => http://profile.ak.fbcdn.net/object2/575/107/t141255783702_3620.jpg

            [host] => Silverstar Casino

            [description] => RSVP attending this event and stand a chance to win 2 tickets to watch Steve Hofmeyr perform live Saturday, December 12th.

            [event_type] => Music/Arts

            [event_subtype] => Concert

            [start_time] => 1260676800

            [end_time] => 1260680400

            [creator] => 138907126863

            [update_time] => 1256035237

            [location] => Silverstar Centre

            [venue] => Array

                (

                    [street] => 

                    [city] => 

                    [state] => 

                    [country] => 

                )



            [privacy] => OPEN

            [hide_guest_list] => 0

            [show_in_search] => 0

        )

Then i display them using the following

// check the result is loop-able
if (is_array($events) && !empty($events)) {
	
	$events = array_slice($events, 0,5);
	
	foreach ($events as $event) {
		
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>event_image</fb:tag-attribute>
			<fb:tag-body>
				<fb:tag name='img'><fb:tag-attribute name='src'>".$event["pic"]."</fb:tag-attribute></fb:tag>
			</fb:tag-body>	
		  </fb:tag>";
	// Right Container
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>event_details</fb:tag-attribute>
			<fb:tag-body>";
	echo "<fb:eventlink eid=".$event["eid"]." /><br/>";
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>text_standout</fb:tag-attribute> 
			<fb:tag-body> 
				<fb:tag name='div'><fb:tag-attribute name='class'>txt_event_heading</fb:tag-attribute>
					<fb:tag-body> 
						Type:
					</fb:tag-body>
				</fb:tag>  
				".$event["event_type"].
			"</fb:tag-body>
		  </fb:tag>";
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>text_standout</fb:tag-attribute> 
			<fb:tag-body> 
				<fb:tag name='div'><fb:tag-attribute name='class'>txt_event_heading</fb:tag-attribute>
					<fb:tag-body> 
						When:
					</fb:tag-body>
				</fb:tag>
		  <fb:date t='".$event["start_time"]."' format='monthname_time' tz='GMT+2' /></fb:tag-body></fb:tag>";
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>text_standout</fb:tag-attribute> 
			<fb:tag-body> 
				<fb:tag name='div'><fb:tag-attribute name='class'>txt_event_heading</fb:tag-attribute>
					<fb:tag-body> 
						Location:
					</fb:tag-body>
				</fb:tag> "
		  .$event["location"]."</fb:tag-body></fb:tag>";
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>text_standout</fb:tag-attribute> 
		<fb:tag-body> 
				<fb:tag name='div'><fb:tag-attribute name='class'>txt_event_heading</fb:tag-attribute>
					<fb:tag-body> 
						Description:
					</fb:tag-body>
				</fb:tag> "
	  .$event["description"]."</fb:tag-body>
	  </fb:tag>";
	echo "</fb:tag-body></fb:tag>";
		
	} // foreach

} // if

Heres my issue. I would like to sort the arrays by ["start_time"], so that when i display them, they are in order from soonest to latest.

Any help would be seriously appreciated. Thanks in advance.

use array_multisort($targetArray,SORT_ASC)

function multi_sort($tab,$key){
    $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] > $b["'.$key.'"]) ? -1 : 1;}');
    usort($tab,$compare) ;
    return $tab ;
}

This will do the job for you

Hi Deon,

Thanks for your help. Ending up going with the following, that works quite well

// Get event arrays
$today = time();
$events = $facebook->api_client->events_get('138907126863','','$today','','');

// Sort arrays
	//Function used to sort array
	function csort($array, $column) {
		$s = array();
		foreach($array as $row) {
			$s[] = $row[$column];
		}
		array_multisort($s, SORT_ASC, SORT_NUMERIC, $array);
	return $array;
	}
$events_sorted = csort($events, 'start_time');	

// Slice sorted arrays
$events_slice = array_slice($events_sorted, 0, 1);																						

// Used the sorted arrays to echo data

foreach ($events_slice as $event) {
	echo time();
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>event_image</fb:tag-attribute>
			<fb:tag-body>
				<fb:tag name='img'><fb:tag-attribute name='src'>".$event["pic"]."</fb:tag-attribute></fb:tag>
			</fb:tag-body>	
		  </fb:tag>";
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>event_details</fb:tag-attribute>
			<fb:tag-body>";
	echo "<fb:eventlink eid=".$event["eid"]." /><br/>";
	echo "<fb:tag name='div'><fb:tag-attribute name='class'>text_standout</fb:tag-attribute> 
			<fb:tag-body> 
				<fb:tag name='div'><fb:tag-attribute name='class'>txt_event_heading</fb:tag-attribute>
					<fb:tag-body> 
						When:
					</fb:tag-body>
				</fb:tag>
		  <fb:date t='".$event["start_time"]."' format='monthname_time' tz='GMT+2' /></fb:tag-body></fb:tag>";
														
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.