php :/

Associate
Joined
26 Jan 2006
Posts
1,502
I need to furnish an identical function to asort($list) of PHP. However, I am not sure how to handle a mix of strings and numbers while sorting.

I could do something like

foreach($list as $value)
if pos > pos+1 swap


a simple bubble sort, but how about an array(1,2, this, 5, is, consufing)?

You can sort this with bubble sort?

Thanks a lot!
 
Specify what sort you want.. int, then string, then other or what?

btw - it's obvious this is an assignment, so please don't expect anyone to do it for you. Post what you have, ask specific questions (i.e. not "can someone do this for me?") and I will be happy to assist. Others will feel the same I'm sure.
 
code wont help me, thats why I talked psudo code in the fist place :)

I aim to learn not copy.

OK, the problem is that I can sort an array if its only integers!

However, if there is a mixure of strings, integers, doubles how i can compare the pairs and implement a bubble sort?

For example,

if (test > 1) what will yield?
 
Well this is what you need to clarify - you already know what the outcome should be, so what would array(1,2,'a','four',12); result in? What result are you looking to achieve?
 
basically, I need to sort Strings in alphabetical order only for now.

You think I need to visit every position in the string and determine that by comparing it to all others? or there is an easier way?
 
Well, as you have to do it all manually, and avoid any of the sort commands - it's looking likely.

I can't remember off the top of my head if you can do "if ('a' < 'b')" but you can short-cut it by converting to ASCII number, or hex, and compare that way.
 
Back
Top Bottom