Solved

Problems using sort() function

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now