There is no any function in php by which we can convert an string alphabets to alphabetical order. This is some sort of coding challenge or you may face it in some interviews or tests as well. I’m writing the code below that return alphabetical order characters what so ever you submit in to the text box.
Code Example:
<?php ini_set('display_errors', 0); error_reporting(E_ERROR | E_WARNING | E_PARSE); ?><form action="" method="post"> Enter time : <input type="text" name="txt" /> <input type="submit" name="sbt" /> </form> <?php $string = $_POST['txt']; $i = 97; $a = ""; for ($i ; $i<123 ; $i++){ $j = strlen($string); $k=0; for ($k ; $k<=$j ; $k++){ if (ord($string[$k]) == $i){ $a .= $string[$k]; } } } echo $a; ?>
Result:
In the end you will get the string in an alphabetical order.