473,387 Members | 1,700 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,387 software developers and data experts.

sorting array...i

Hi,
I am getting confused with sorting arrays...
$arraytest =array(5) { [0]=string(2) "39" [1]=string(2) "44" [2]=>
string(2) "77" [3]=string(3) "150" [4]=string(3) "464" }

why do i get NULL value if i try to sort this array using sort command?

sort($arraytest);
Thanks for your help!
VooDoo
Nov 20 '07 #1
4 1630

"VooDoo" <Vo*********@free.frwrote in message
news:fh**********@reader1.imaginet.fr...
Hi,
I am getting confused with sorting arrays...
$arraytest =array(5) { [0]=string(2) "39" [1]=string(2) "44" [2]=>
string(2) "77" [3]=string(3) "150" [4]=string(3) "464" }

why do i get NULL value if i try to sort this array using sort command?

sort($arraytest);
poorly asked question.

sort() performs a sort on the $array parameter by reference. sort() does NOT
return the sorted version of $array as a result of its operation. so...

<?
$array = array(
'39' ,
'44' ,
'77' ,
'150' ,
'464'
);
sort($array);
echo '<pre>' . print_r($array, true) . '</pre>';
?>

will print the array and show that the values are sorted from lowest to
highest.

btw, leave out the array(5) string(2) [0]=shit. it makes reading the code
a pain in the ass and isn't needed in the least...it doesn't make any impact
on the way php executes that code. if coded like the above, you can easily
see what *actual* values are making up the members of the array...rather
than trying to weed out the other junk surrounding them (like what index it
has or what data-type you are *casting* it to). the extra crap is feckless
and less than useful.
Nov 20 '07 #2
On Tue, 20 Nov 2007 16:32:13 +0100, VooDoo <Vo*********@free.frwrote:
Hi,
I am getting confused with sorting arrays...
$arraytest =array(5) { [0]=string(2) "39" [1]=string(2) "44"[2]=>
string(2) "77" [3]=string(3) "150" [4]=string(3) "464" }

why do i get NULL value if i try to sort this array using sort command?

sort($arraytest);
Probably, because sort() works by reference, not return:

$arraytest = sort($arraytest);
//=>$arraytest = true or false; $arraytest[N] = NULL

sort($arraytest);
//=>$arraytest = sorted array; $arraytest[N] = set value or NULL if
non-existant
--
Rik Wasmus
Nov 20 '07 #3
Ok thanks for your replies.
So the sort its working, I do not need to affect it to a var, just call the
function...

Sorry for the extra crap it was the outpout of a var_dump as i could not
understand what was wrong.
Thanks
Voodoo
Nov 21 '07 #4

"VooDoo" <Vo*********@free.frwrote in message
news:fi**********@reader1.imaginet.fr...
Ok thanks for your replies.
So the sort its working, I do not need to affect it to a var, just call
the function...
right.
Sorry for the extra crap it was the outpout of a var_dump as i could not
understand what was wrong.
Thanks
no problem.
Nov 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Kirby | last post by:
Hello All I am trying to update me code to use arrays to store a group of information and I have come up with a problem sorting the multiple array :( Array trying to sort: (7 arrays put into...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
3
by: SilverWolf | last post by:
I need some help with sorting and shuffling array of strings. I can't seem to get qsort working, and I don't even know how to start to shuffle the array. Here is what I have for now: #include...
7
by: Foodbank | last post by:
Hi everyone. I'm having trouble with this radix sorting program. I've gotten some of it coded except for the actual sorting :( The book I'm teaching myself with (Data Structures Using C and...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
5
KevinADC
by: KevinADC | last post by:
Introduction This discussion of the sort function is targeted at beginners to perl coding. More experienced perl coders will find nothing new or useful. Sorting lists or arrays is a very common...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.