Default TemplateGreen TemplateBlue TemplateRed TemplateGold TemplateBlue Gloss Template
Sri Lanka News Categories

Mycities Network
PHP Scripts Examples and Tutorials
Sort Array By String Length

Tuesday Aug 22, 2006
This function provides a way to sort an array by string length.

<?php

$array
= array('0'=>'x', '1'=>'xx', '2'=>'xxx'
);

usort($array, "strlensort"
);

echo
'<pre>'
;
print_r($array
);
echo
'</pre>'
;


function
strlensort($a, $b
) {
        if (
strlen($a) == strlen($b
)) {
              return
0
;
        }
        return (
strlen($a) > strlen($b)) ? -1 : 1
;
}

?>



Comments : What do you think about this news?
No Comments yet.

POST COMMENT
Name
Message
  Post will be visible after admins approval
 
Members Login
User ID
Password
    Register
Forgot password?

SriLankaWebHosting.com
Just for (Rs.500) $5 per month

Your own domain name, 1GB Space, Unlimited Email Address, Sri Lankan Support & for more info call us.
077-989-5368, 072-829-9077




Join Sri Lanka Banner Exchange | Text Link | Resources - Top Link Exchange