PHP Sort : How to write PHP sort for array
Simple sort keyword to sort array in sorted order
Syntax :
<!DOCTYPE html>
<html>
<title> Simple PHP Array Sort for Alphabet </title>
<body>
<?php
$alphabets= array("a", "b", "c");
sort($alphabets);
$alph_length= count($alphabets);
for($i = 0; $i < $alph_length; $i++) {
echo $alphabets[$i]."<br>";
}
?>
</body>
</html>
Output:
a
b
c
<!DOCTYPE html>
<html>
<title> Simple PHP Array Sort for Number </title>
<body>
<?php
$numbers= array(1, 3, 2);
sort($numbers);
$num_length= count($numbers);
for($i = 0; $i < $num_length; $i++) {
echo $numbers[$i]."<br>";
}
?>
</body>
</html>
Output:
1
2
3
Syntax :
<!DOCTYPE html>
<html>
<title> Simple PHP Array Sort for Alphabet </title>
<body>
<?php
$alphabets= array("a", "b", "c");
sort($alphabets);
$alph_length= count($alphabets);
for($i = 0; $i < $alph_length; $i++) {
echo $alphabets[$i]."<br>";
}
?>
</body>
</html>
Output:
a
b
c
<!DOCTYPE html>
<html>
<title> Simple PHP Array Sort for Number </title>
<body>
<?php
$numbers= array(1, 3, 2);
sort($numbers);
$num_length= count($numbers);
for($i = 0; $i < $num_length; $i++) {
echo $numbers[$i]."<br>";
}
?>
</body>
</html>
Output:
1
2
3
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a comment