tefflox Posted August 3, 2006 Share Posted August 3, 2006 the code is meant to echo a line of 50 characters made of long dashes and nbsp's, but it only echoes a single random number. How can I get this code to echo the string that I need?[code]function flow() { $ar = array( 0 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f); $count = 0; $output = ""; while($count < 50) { $numSpaces = rand(0, 9); for($i = 0; $i < $numSpaces, $count < 50; $i++) { $output += " "; $count++; } $r1 = $ar[rand(0, 15)]; $r2 = $ar[rand(0, 15)]; $g1 = $ar[rand(0, 15)]; $g2 = $ar[rand(0, 15)]; $b1 = $ar[rand(0, 15)]; $b2 = $ar[rand(0, 15)]; $col = $r1.$r2.$g1.$g2.$b1.$b2; //$output += "<span style=\"color:#\".$col."\">——</span>"; $output += "<span style=\"color:#\""; $output += $col; $output += "\">——</span>"; $count = $count + 2; } echo $output; } // end flow[/code] Link to comment https://forums.phpfreaks.com/topic/16396-need-help-with-a-loop-generated-html-stringecho/ Share on other sites More sharing options...
hitman6003 Posted August 3, 2006 Share Posted August 3, 2006 In this line:[code]$ar = array( 0 => 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f);[/code]you need to put the letters in quotes.You are using += when you should be using .= . += will add the value of two numbers together...[code]$a = 1;$b = 2;$a += $b;echo $a; //results in 3;[/code]The .= operator will concatenate two strings. Link to comment https://forums.phpfreaks.com/topic/16396-need-help-with-a-loop-generated-html-stringecho/#findComment-68235 Share on other sites More sharing options...
tefflox Posted August 3, 2006 Author Share Posted August 3, 2006 thank you. it's working fine now. :) Link to comment https://forums.phpfreaks.com/topic/16396-need-help-with-a-loop-generated-html-stringecho/#findComment-68240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.