473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to sort array values

Anyone know how to sorting array values from least to greatest. Here the code;

[PHP]function mulsort($a)
{
sort($a);
$c = count($a);
for($i = 0; $i < $c; $i++)
if (is_array($a[$i]))
mulsort($a[$i]);
}

$temp = array(5,4,1,3,2);
$test = array();

$test = mulsort($temp);

for($i=0; $i<sizeof($test); $i++)
{
echo $test[$i].'<br>';
}[/PHP]
Oct 2 '07 #1
1 1555
Atli
5,058 Expert 4TB
Hi.

Have you tried the sort() function?
Seems to work on my test server (tho it messes up the index values):
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $temp = array(5,4,1,3,2);
  3.     sort($temp, SORT_NUMERIC);
  4.  
  5.     echo "<pre>";
  6.     print_r($temp);
  7.     echo "</pre>";
  8. ?>
  9.  
Outputs:
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [0] => 1
  4.     [1] => 2
  5.     [2] => 3
  6.     [3] => 4
  7.     [4] => 5
  8. )
  9.  
Oct 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: ritchie | last post by:
Hi all, I am new to this group and I have question that you may be able to help me with. I am trying to learn C but am currently stuck on this. First of all, I have a function for each sort...
6
by: Ali Chambers | last post by:
Hi, I have a two arrays that I wish to sort. One is the index array (full of floating point values). The other is a string array: ARRAY 1 ARRAY 2 ------- -------- -1.2 textA 12 textB...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
6
by: max sharma | last post by:
Hi all, I am using a hashtable for my application. Its similar to word count application. How can I sort the hashtable w.r.t. the VALUE and not the KEY. The sample data of the table is given below...
5
by: Jan Smith | last post by:
I've searched the overloads for the Array.Sort method, and I haven't found a clear answer to my question. Maybe it's not in Array.Sort. Here's the question: I initialize an array X with the...
1
by: aarklon | last post by:
Hi folks, this is the program implementing quicksort #include<stdio.h> #include<stdlib.h> #define swap(a,b){int t; t=a;a=b;b=t;} int partition(int,int,int); void quicksort(int,int,int);
5
by: Military Smurf | last post by:
I have a string array full of values like this: 05 00 0A 5E 4C 40 40 03 00 C0 9F 27 60 57 08 00 C0 9F 36 71 35 01 00 0A 5E 4E 40 13 I want to sort them in an ascending fashion based on...
7
by: ^cypis^ vel. SQ9JTI | last post by:
Hi, i need your help. I have to prepare a homework, easy program, which will be sorting the values from txt file and writing the solution to another txt file. It has to be a bucket sort. Have...
0
Ganon11
by: Ganon11 | last post by:
Earlier, mmccarthy was kind enough to post a short article explaining the Bubble Sort. As she said, this is a relatively slow sorting algorithm. Here, I will attempt to present a slightly faster...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.