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/>"; } ?> Link to comment https://forums.phpfreaks.com/topic/287557-nested-loop-exercise/ Share on other sites More sharing options...
Ch0cu3r Posted April 6, 2014 Share Posted April 6, 2014 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 Link to comment https://forums.phpfreaks.com/topic/287557-nested-loop-exercise/#findComment-1475106 Share on other sites More sharing options...
noob321 Posted April 6, 2014 Author Share Posted April 6, 2014 thanks so much for your help Link to comment https://forums.phpfreaks.com/topic/287557-nested-loop-exercise/#findComment-1475107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.