noob321 Posted April 6, 2014 Share Posted April 6, 2014 HI all i need to write a small nested loop example to output a series of integers in the following format: 1 12 123 1234 12345 where the 1 is 10px, 2 is 20px font size etc. i have got to to output 1,2,3,4,5 but not my above desired output , can anyone point me in the right direction?heres my code: <?php $sizes =array("10px","20px","30px","40px","50px"); for($i = 0, $l = count($sizes); $i < $l; $i++){ $size = $sizes[$i]; $text = $i + 1; echo "<span style='font-size:$size'>$text</span><br/>"; } ?> Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted April 6, 2014 Solution Share Posted April 6, 2014 (edited) You need to concatenated $i + 1 to $text for each iteration of the loop. $text .= $i + 1; // concatenate $i + 1 Before the for loop make sure you initialise $text before hand too ( $text = ''; ) to prevent a notice message. The .= is the concatenation assignment operator Edited April 6, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
noob321 Posted April 6, 2014 Author Share Posted April 6, 2014 thanks so much for your help Quote Link to comment 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.