0

I'm having some troubles sorting events for my website in wordpress. I'm using custom fields to create events with a title, a description and a date. I put every events date in an array:

$datesEvenements = array();
array_push($datesEvenements,get_field('date'));

I then get the timestamp for each date:

foreach($datesEvenements as $value){
    $timestamp = strtotime($value);
    array_push($tsEvenements,$timestamp);
}

I then proceed to sort my timestamp by replacing the past event by 0 or an association of the event timestamp with the difference between that timestamp and the present one.

$arrEventDelta = array();    
for($i=0;$i<count($tsEvenements);$i++){
    $tsi = $tsEvenements[$i];
    if($ts>$tsi){
    array_push($arrEventDelta,0);
}
elseif($ts<=$tsi){
    array_push($arrEventDelta,array('TimestampEvenements'=>$tsi,'DeltaEvenements'=>$deltaTs));
}

After that, I would like to order the array '$arrEventDelta' by the 'DeltaEvenements' value. Unfortunately, I'm a bit confused with all those arrays. I've tried the array_multisort function like so:

$DeltaEvents = array();
foreach($arrEventDelta as $key => $row){
    $DeltaEvents[$key] = $row['DeltaEvents'];
}
array_multisort($DeltaEvents, SORT_ASC, $arrEventDelta);

But it doesn't work. Any tips on how I could fix this?

This is what is outputed from this,

Array ( [0] => 0 [1] => Array ( [TimestampEvenements] => 1394582400 [DeltaEvenements]                  => **31923** ) [2] => Array ( [TimestampEvenements] => 1394668800 [DeltaEvenements] => **118323** )    [3] => 0 [4] => 0 )

I need to order the highlighted numbers in increasing order.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Can you show example data of your array which you would like to sort? – barell Mar 10 '14 at 19:55
  • please use `var_export()` to get the array to share – Emilio Gort Mar 10 '14 at 19:57
  • Make sure you research here at [so]. Particularly, I've never had to ask about this, always finding a ready made solution here. – brasofilo Mar 10 '14 at 20:22
  • Yeah, as both barell and Emilio Gort suggested, please paste the output of the array. I cannot see what it is you are working with. Otherwise, you'd need to go through and tell us what each of the variables are set to in order for us to recreate it. But that seems to be a lot more work on your part and our part than just pasting in your final array. – Quixrick Mar 11 '14 at 14:10
  • Hi, I added the output of this array – Mathieu Désilets Mar 11 '14 at 15:13
  • http://stackoverflow.com/questions/2699086/sort-multi-dimensional-array-by-value?rq=1 Sorted. Thanks a lot. – Mathieu Désilets Mar 11 '14 at 15:47

0 Answers0