?
Solved

Problems using sort() function

Posted on 2008-10-29
2
Medium Priority
?
227 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

770 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