473,545 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1638

"VooDoo" <Vo*********@fr ee.frwrote in message
news:fh******** **@reader1.imag inet.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*********@fr ee.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*********@fr ee.frwrote in message
news:fi******** **@reader1.imag inet.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
2969
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 an array) and I want to sort on Descending. This is displayed using print_r() function. Array
7
3242
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)) CType(local4, Short) = CType(src, Short)
3
6391
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 <stdio.h> void main(void) { char lines; int count = 0, i;
7
10074
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 C++) just doesn't explain things good at all and the tutorials I've viewed don't really explain least significant digit first sorting or show examples,...
0
3218
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 way... here is my code on how I did it to help anyone starting out get an idea of how to use virtual mode in ..NET 2.0 Imports...
7
4803
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 expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want...
5
6672
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 requirement of programs. If you don't know the difference between a list and array don't worry about it. A list is just an array without a name. They...
1
7170
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 methods or syntax to a less experienced perl coder. I will post links to online resources you can read if necessary. Experienced perl coders might find...
5
3166
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 search algorithms that can be used are Linear Search and Binary Search. The sorting algorithms are bubble, selection and Insertion sort. First, the user...
5
4910
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link:...
0
7470
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7811
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7428
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7760
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5334
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3455
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.