473,508 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting string-array without case...

Hi!

I user sort() but it gives me all uppercase items first.
Looking at http://ee.php.net/manual/en/function.sort.php I cannot find
what I need - tried natcasesort, but that was even more
interesting....

sort gives me (yes, I am aware of the spelling error)

Doc manager
Doc manger more
Tango
brugs

while natcasesort gives me

Doc manager
Tango
Doc manger more
brugs

and I want

brugs
Doc manager
Doc manger more
Tango

just as my alphabet is :-)
What should I user...
Jan 16 '08 #1
2 1506
On Jan 16, 10:40 am, jodleren <sonn...@hot.eewrote:
Hi!

I user sort() but it gives me all uppercase items first.
Looking athttp://ee.php.net/manual/en/function.sort.phpI cannot find
what I need - tried natcasesort, but that was even more
interesting....

sort gives me (yes, I am aware of the spelling error)

Doc manager
Doc manger more
Tango
brugs

while natcasesort gives me

Doc manager
Tango
Doc manger more
brugs

and I want

brugs
Doc manager
Doc manger more
Tango

just as my alphabet is :-)
What should I user...
How about this (untested):

$arr = array('foo', 'bar', 'Baz');
usort($arr, create_function('$v1,$v2', 'return strcasecmp($v1,
$v2);'));
Jan 16 '08 #2
On Jan 16, 6:49*pm, ZeldorBlat <zeldorb...@gmail.comwrote:
On Jan 16, 10:40 am, jodleren <sonn...@hot.eewrote:


Hi!
I user sort() but it gives me all uppercase items first.
Looking athttp://ee.php.net/manual/en/function.sort.phpIcannot find
what I need - tried natcasesort, but that was even more
interesting....

How about this (untested):

$arr = array('foo', 'bar', 'Baz');
usort($arr, create_function('$v1,$v2', 'return strcasecmp($v1,
$v2);'));- Hide quoted text -
Yep, that does it. Thanks

I implemented it as this, which makes it work as a normal sort.

function my_sort(&$arr)
{
usort($arr, create_function('$v1,$v2', 'return
strcasecmp($v1,$v2);'));
}
Jan 17 '08 #3

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

Similar topics

4
2518
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
12
2365
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
8
2247
by: nidhog | last post by:
Hello guys, I made a script that extracts strings from a binary file. It works. My next problem is sorting those strings. Output is like: ---- snip ---- 200501221530
7
4213
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't...
4
1695
by: Richard | last post by:
When i try sorting in the database, it sorts the numbers: 0 1 102 2 304 305 4 etc....
19
25424
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
2
7208
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column...
0
1756
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
1
2165
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
6
2394
by: carlos123 | last post by:
I have a programming assignement that i have been working on for quite some time now. I need your guys' help. My assignement is to great a table with data in it. and it will have a combobox and 2...
0
7124
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...
0
7498
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...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4707
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...
0
3195
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...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.