mithu_sree Posted December 13, 2006 Share Posted December 13, 2006 I have some code like this for displayng an A-Z anchor table[code]function make_anchors_index() { echo "<table class=\"anchor\"> <tr>"; for($i = 'A'; $i < 'Z'; $i++) echo "<td><a href=\"#".$i."\">".$i."|</a></td>"; echo "<td><a href=\"#".$i."\">".$i."</a></td>"; echo "</tr></table><br />";}[/code]This one produces a list of A-Z anchorsand when i mordified this to [code]function make_anchors_index() { echo "<table class=\"anchor\"> <tr>"; for($i = 'A'; $i <= 'Z'; $i++) echo "<td><a href=\"#".$i."\">".$i."|</a></td>"; echo "</tr></table><br />";}[/code]produces A|B|C....Y|Z|AA|AB|AC...Why is this?How can i display A|B|..Z list using only one echo "<td><a href=\"#".$i."\">".$i."|</a></td>";statment mordifying only the for loop codition?? Link to comment https://forums.phpfreaks.com/topic/30439-a-z-anchor-list/ Share on other sites More sharing options...
trq Posted December 13, 2006 Share Posted December 13, 2006 You'll want to use a range. eg;[code=php:0]foreach (range('A','Z') as $i) {[/code] Link to comment https://forums.phpfreaks.com/topic/30439-a-z-anchor-list/#findComment-140178 Share on other sites More sharing options...
mithu_sree Posted December 13, 2006 Author Share Posted December 13, 2006 Thanks very muchI need to know a little about why $i <= 'Z' not works? Link to comment https://forums.phpfreaks.com/topic/30439-a-z-anchor-list/#findComment-140182 Share on other sites More sharing options...
trq Posted December 13, 2006 Share Posted December 13, 2006 ++ is the post incriment operator designed to add 1 to an integer. I suspect php will let you incriment a thru z with it, but its not really its designed purpose so maybe the <= has some unexpected behavour. Link to comment https://forums.phpfreaks.com/topic/30439-a-z-anchor-list/#findComment-140183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.