In this post we are going to discuses about alphabet navigation.before that do you know generating alphabets in a loop.if don’t know look at below example once
3 |
for ($i=65; $i<=90; $i++) { |
4 |
echo chr($i);// chr returns specific character |
5 |
//out put :ABCDEFGHIJKLMNOPQRSTUVWXYZ |
In the above example chr() function returns specific character & chr() also accepts negative numbers as an ascii code[char(-100)]
You can make above output with range() function,look the example :
1 |
<?php foreach(range('A','Z') as $i) { |
output:ABCDEFGHIJKLMNOPQRSTUVWXYZ
now you can easily understand below alphabet navigation menu
2 |
$LetterList = range('A','Z'); |
3 |
foreach ($LetterList as $litter) { |
Outpup : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
you can make above output in another way
2 |
$LetterList = array_merge(array('0-9'),range('A','Z')); |
3 |
foreach ($LetterList as $value) { |
out put:A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
The description of the functions used in this tutorial are as follows
chr() this function return a spesific character
range() this function crate an array containing range of elements
foreach()foreach is used to loop over all elements of an array
array_merge() this function merges one or more arrays
No comments:
Post a Comment