Solved

Problems using sort() function

Posted on 2008-10-29
2
219 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

740 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