Re: [PHP] Sort by string length...

2004-12-21 Thread David Otton
On Tue, 21 Dec 2004 16:18:52 -0500 (EST), you wrote: >Any idea how to sort an array by string length? You write a function that compares two strings (A and B), and returns 0 if len(A) == len(B), -1 if len(A) < len(B) or +1 if len(A) > len(B). function compare_by_length ($a, $b) { $la = strle

Re: [PHP] Sort by string length...

2004-12-21 Thread tg-php
Is it an associative array? That is, are you assigning values like this: Method 1: $arr[] = "some text string"; or $arr = array("some text string","some text string too"); or like this... Method 2: $arr["value1"] = "some text string"; or $arr1 = array("value1"=>"some text string","value2"=>"som

Re: [PHP] Sort by string length...

2004-12-21 Thread ApexEleven
How about iterating though the strings and putting string values and lengths in an array: [begin untested code] $strings = array('i','am','who'); $string_count = array(); foreach ($strings as $string) { $string_count['value'][] = $string; $string_count['length'][] = strlen($string); } array_mult

Re: [PHP] Sort by string length...

2004-12-21 Thread Chris
One of the Array sort functions? http://www.php.net/usort Russell P Jones wrote: Any idea how to sort an array by string length? Russ Jones -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Sort by string length...

2004-12-21 Thread Jason Wong
On Wednesday 22 December 2004 05:18, Russell P Jones wrote: > Any idea how to sort an array by string length? usort(), strlen() -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development

Re: [PHP] Sort by string length...

2004-12-21 Thread Tom Rogers
Hi, Wednesday, December 22, 2004, 7:18:52 AM, you wrote: RPJ> Any idea how to sort an array by string length? RPJ> Russ Jones With a user defined sorting function something like this -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.ne

RE: [PHP] Sort by string length...

2004-12-21 Thread Michael Sims
Russell P Jones wrote: > Any idea how to sort an array by string length? Use usort() in conjunction with a user defined function that compares the length of both strings using strlen(). If brevity at the (possible) expense of clarity is your thing, you can even use create_function() as your call