evankennedy Posted October 6, 2007 Share Posted October 6, 2007 Hello, I am working on a project for my server scripting class, and I need some help. First off, I want to show you what we already know in this class so you don't say to do some crazy thing we haven't learned yet. If Else statements Variables Arrays For loops I think thats mostly what we know except for a few basic things. What I am trying to do is to output a specified letter through asterics. Here is are a few examples of outputs. ***** ***** ***** * * * * * ***** ***** * * * * * * * * ***** ***** A B C now a few things come to mind when you think about this. The first is probably just saying if ($letter=="a"){echo "Asterics for A";} I already am aware of this method and I am wondering if there is a way to do this with an array or with a for loop. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/72061-help-with-school-project/ Share on other sites More sharing options...
teng84 Posted October 6, 2007 Share Posted October 6, 2007 that is hard to do with loop (very loooong)or array but if its ok not to use them then maybe you can try this $a1='****'; $a2='***'; $a3='**'; $a4='*'; $a5 = '* *' $a6= ' *'; //print A then echo $a1.'<br>'; echo $a5.'<br>'; echo $a1.'<br>'; echo $a5.'<br>'; echo $a5.'<br>'; you cant have your code dynamic but like one loop to cover all letter you have to have a code for each letters Quote Link to comment https://forums.phpfreaks.com/topic/72061-help-with-school-project/#findComment-363132 Share on other sites More sharing options...
BradGushurst Posted October 6, 2007 Share Posted October 6, 2007 <?php $output = "abcdefghi"; $letterTemplate[1] = '*****'; $letterTemplate[2] = '* *'; $letterTemplate[3] = '* '; $letterTemplate[4] = ' *'; $letterTemplate[5] = ' **'; $letterTemplate[6] = '*** '; $letterTemplate[7] = '*  **'; $letterTemplate[8] = ' * '; $letterLayout['a'] = '12122'; $letterLayout['b'] = '12121'; $letterLayout['c'] = '13331'; $letterLayout['d'] = '12221'; $letterLayout['e'] = '13131'; $letterLayout['f'] = '13633'; $letterLayout['g'] = '13721'; $letterLayout['h'] = '22122'; $letterLayout['i'] = '18881'; $outputLetters = str_split($output); foreach( $outputLetters as $letter ) { $lines = str_split( $letterLayout[strtolower($letter)] ); foreach( $lines as $line ) { echo $letterTemplate[$line] . '<br />'; } echo "-----<br />"; } ?> Just continue to fill out the arrays for the templates and the layouts and it will print any combination of letters you would like. You probably want to wrap the letter output in a dive or a table in order to make it go horizontal across the page, other then that the code should work flawlessly. Any questions just let me know. Quote Link to comment https://forums.phpfreaks.com/topic/72061-help-with-school-project/#findComment-363171 Share on other sites More sharing options...
MasterACE14 Posted October 6, 2007 Share Posted October 6, 2007 you could also put each letter into a function so its much easier to echo words onto a page, instead of copying and pasting the same code over and over again Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/72061-help-with-school-project/#findComment-363398 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.