Anglais Francais Prosygma 

Italie
-
    hebergement 

asp
prosygma_logo



 Divers (1)  Chaînes (31)  Dates (18)  Nombres (8)  Structures (5) 
 Tableaux (6) 
array - invArray/array_reverse - join/implode - multiSort/sort - split/explode - ubound/sizeof
MULTISORT/SORT 
Trie un tableau
ASP <Doc> 
<% ' Merci Aurelien !
Function MultiSort(ByVal inARRAY, inCOL, inORDER)
  ' Cette function renvoie un Array
  '   - inARRAY : Array de depart
  '   - inCOL     : Position de la colonne de tri
  '   - inORDER : Ordre de tri
 nbC = UBound(inARRAY, 1)
 nbR = UBound(inARRAY, 2)
 ReDim aOut(nbC, nbR)
 ' On passe le premier
 For i = 0 To nbC
  aOut(i, 0) = inARRAY(i, 0)
 Next
 lastIns = 1
 ' On passe tout le reste
 For i = 1 To nbR
  ' Ou on insere ?
  swapPos = -1
  ' Dans quel sens on tri ?
  If UCase(inORDER) = "ASC" Then
   For j = 0 To nbR
    If StrComp(inARRAY(inCOL,i),aOut(inCOL,j),1)<0 Then
     swapPos = j
     Exit For
    End If
   Next
  Else
   For j = 0 To nbR
    If StrComp(inARRAY(inCOL,i),aOut(inCOL,j),1)>0 Then
     swapPos = j
     Exit For
    End If
   Next
  End If
  If swapPos = -1 Then
   For j = 0 To nbC
    aOut(j, lastIns) = inARRAY(j, i)
   Next
  Else
   For j = nbR To swapPos Step -1
    For k = 0 To nbC
     If j <> 0 Then
      aOut(k, j) = aOut(k, j - 1)
     End If
    Next
   Next
   For j = 0 To nbC
    aOut(j, swapPos) = inARRAY(j, i)
   Next
  End If
  lastIns = lastIns + 1
 Next
 MultiSort = aOut
End Function

tableau2 = multisort(tableau, 0, "ASC")
%>

PHP <Doc> 
<?
$tableau2=sort($tableau);
?>

Voir aussi array_multisort()
JavaScript <Doc> 
<script>
tableau2=tableau.sort()
</script>

© ASP-PHP.net 11/01/2003