Miqayel Posted October 8, 2014 Share Posted October 8, 2014 How to build this whit Php loops * *********************************** * ** *** **** ***** ****** *************** *********************************** * ******** ******* ****** ***** **** *** ** * Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/ Share on other sites More sharing options...
Jacques1 Posted October 8, 2014 Share Posted October 8, 2014 This is not the place where you just lean back and let others do your homework. You do the work, we just help. So what's the pattern? What have you tried? What are your thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493026 Share on other sites More sharing options...
Ch0cu3r Posted October 8, 2014 Share Posted October 8, 2014 (edited) Here is a starting point http://php.net/for. Learn how to use a for loop and have a go at it yourself. Get stuck and we will try to help you. We WILL not provide code for you. Copy and pasting code will not teach you how to program. Understanding the problem and actually writing code is what helps you to learn to program. What you are attempting to do is something that anyone can achieve if you have learned the very basics of PHP. The PHP documentation is a great resource for you if you are new to the language. Edited October 8, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493027 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 i'm not waited that you will do my homework instead of me . i done this $x=null; for ($i=0; $i <= 8 ; $i++) { echo $x .'*' .'<br>' ; $x.='*'; } but it doesn't work with others Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493107 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 Can i do something like this ? For exsample $x = '        ' $y = $x - ' ' or something that will work with this principle Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493109 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 And one more thing: i can't use arrays. Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493111 Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2014 Share Posted October 9, 2014 i'm not waited that you will do my homework instead of me . i done this $x=null; for ($i=0; $i <= 8 ; $i++) { echo $x .'*' .'<br>' ; $x.='*'; } but it doesn't work with others That is a good start. For the others you will need to write separate for loops for outputting the remaining patterns. Afterwards consider re-factoring your code into reusable functions Can i do something like this ? You can pad the string with whatever characters you want. You don't have to pad your lines with . Your could instead apply white-space: pre CSS styling to the HTML element your patterns are contained in. And one more thing: i can't use arrays. Who mentioned arrays? I see no need for arrays in this exercise. A for loop is all that is required. You may find the following functions helpful str_repeat and str_pad as well. Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493130 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 How can i do this ??? for ($i=1; $i < 9 ; $i++) { $x.='*'; so echo $x when $i = 8 afther echo $x when $i =7 ...and so on }; Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493137 Share on other sites More sharing options...
ginerjm Posted October 9, 2014 Share Posted October 9, 2014 Sure sounds like you want someone to write this for you. If you are attempting to learn php or even learn how to program, you have to do the learning yourself. There is a certain amount of intelligence that has to be used to do this kind of work, and that use begins in the beginning. Good luck. You may get some well-meaning reader here who will jump right in and solve this problem for you, but I feel that would be a serious injustice to your learning process. Besides - why are even attempting this exercise? Did you dream this up? If so, why did you start with such a tricky project? Try something simpler to get comfortable with writing simple php and solving simple problems. Or is this actually 'homework'? Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493138 Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2014 Share Posted October 9, 2014 How can i do this ??? for ($i=1; $i < 9 ; $i++) { $x.='*'; so echo $x when $i = 8 afther echo $x when $i =7 ...and so on }; A for loop can also count backwards too. To so you'd use the opposite operators for each expression. The < operator means less than. The opposite operator would be the > (greater than) operator $i++ means increment $i by one. The opposite operator would be $i-- which means deincrement $i by one. Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493142 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 Sure sounds like you want someone to write this for you. If you are attempting to learn php or even learn how to program, you have to do the learning yourself. There is a certain amount of intelligence that has to be used to do this kind of work, and that use begins in the beginning. Good luck. You may get some well-meaning reader here who will jump right in and solve this problem for you, but I feel that would be a serious injustice to your learning process. Besides - why are even attempting this exercise? Did you dream this up? If so, why did you start with such a tricky project? Try something simpler to get comfortable with writing simple php and solving simple problems. Or is this actually 'homework'? You honestly irritate me How much can you talk about self-directed learning?? I just missed the lesson because I was sick!!! Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493145 Share on other sites More sharing options...
ginerjm Posted October 9, 2014 Share Posted October 9, 2014 Not my problem. Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493156 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 I found this but don't know what do next , while($a++<10) { $c=str_pad(base_convert($a, 10, 2), 2, "0", STR_PAD_LEFT); $b=strtr($c, "01", " *"); echo $b."\r\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493158 Share on other sites More sharing options...
Miqayel Posted October 9, 2014 Author Share Posted October 9, 2014 and this $c = null; $a="*"; $b=7; while($b-->0) { $c.=$a; $d[]=$c; } $e =array_reverse($d); foreach($e as $v) { echo $v."\r\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493159 Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2014 Share Posted October 9, 2014 Did you miss reply #10? Also why are you posting code which a) you did not write and b) has no relevance to your problem. Quote Link to comment https://forums.phpfreaks.com/topic/291507-help-me-please/#findComment-1493175 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.