sort()
General Example 1.
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
reset($fruits);
while (list($key, $val) = each($fruits)) {
echo "fruits[".$key."] = ".$val."n";
}
?>
Directory Example 1. A simple scandir() example
$dir = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
/* Outputs something like:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)
*/
?>
Directory Example 2. PHP 4 alternatives to scandir()
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
rsort($files);
print_r($files);
/* Outputs something like:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)
*/
?>
NewSourceMedia is providing links to these listings as
a courtesy, and makes no representations regarding the content or
any information related thereto. Any questions, complaints or claims
regarding the downloaded content or details must be directed to the appropriate
publisher. We do not encourage or condone the use of any
software in violation of applicable laws.