Skip to content

Instantly share code, notes, and snippets.

@putheakhem
Created November 6, 2019 15:34
Show Gist options
  • Save putheakhem/a35e63495f3212c84a84591f73aa8854 to your computer and use it in GitHub Desktop.
Save putheakhem/a35e63495f3212c84a84591f73aa8854 to your computer and use it in GitHub Desktop.
Store these colors in array: 'red', 'green', 'blue', 'yellow', 'purple' as $colors then update your list of colors to be sorted in alphabetical order.
<!--
Store these colors in array: 'red', 'green', 'blue', 'yellow', 'purple'
as $colors then update your list of colors to be sorted in alphabetical order.
-->
<?php
$colors = array(
"red",
"green",
"blue",
"yellow",
"purple",
);
echo "<h4>before sort </h4>";
$arraylength = count($colors);
for($x = 0; $x < $arraylength; $x++) {
echo $colors[$x] . "<br>";
}
sort($colors);
echo "<h4>After sort </h4>";
$arraySortLength = count($colors);
for($x = 0; $x < $arraySortLength; $x++) {
echo $colors[$x] . "<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment