Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Saturday, January 8, 2011

Sort An Array of String Without Using PHP Function

To sort an array of string without using php function?

try this...

$str = array(“Z”,”c”,”A”,”C”,”E”,”B”,”M”,”N”);
$array_length = sizeof($str);

for($x = 0; $x < $array_length; $x++) {

for($y = 0; $y < $array_length; $y++) {

if(strcasecmp($str[$x],$str[$y])<0) {

$hold = $str[$x];
$str[$x] = $str[$y];
$str[$y] = $hold;
}
}
}

echo "<pre>”;
print_r($str);
echo “</pre>”;