Solved

Problems using sort() function

Posted on 2008-10-29
2
222 Views
Last Modified: 2012-05-05
Hi there,

I'm trying to sort an array in ASC order, by doing the following operations, but instead of outputing a sorted array, i get a "1" integer...

Here's what returns print_r($a)

before sorting :

Array ( [0] => . [1] => .. [2] => accueil_php.php [3] => commande.php [4] => configure.php [5] => connect.php [6] => connexion.php [7] => database_tables.php [8] => date-heure.php [9] => db_funcs.php [10] => eachtest.php [11] => errors.php [12] => form_mail.php [13] => form_selection.php [14] => formulaire.php [15] => functions.php [16] => image.php [17] => insert_test.php [18] => ipaddr.php [19] => membres.php [20] => multiples.php [21] => news.php [22] => poubelle.php [23] => rand.php [24] => resultat.php [25] => sites.php [26] => string_compare.php [27] => tableau_associatif.php [28] => tableau_associatif_each.php [29] => tableau_associatif_foreach.php [30] => upload [31] => upload.php [32] => viewnews.php )

After sorting :

1

And i get the same result using array_multisort or any other sorting function...

That's making me crazy!

Can someone help ?

Thx

Terence
$a=scandir('.');
$a=sort($a);

Open in new window

0
Comment
Question by:terencepires
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 22836593
The sort() function sorts the array inplace. Try this:
$a=scandir('.');
sort($a);
print_r($a);

Open in new window

0
 
LVL 1

Author Closing Comment

by:terencepires
ID: 31511469
thanks :)
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question