dubstyleenation Posted September 13, 2007 Share Posted September 13, 2007 I need to echo this statement c=a1+a2+a3; when I try, I only get a1a2a3. $count = $_POST['count']; for($i = 1; $i <= $count; $i++) { //$count in this case is 3. $count is never bigger than 6. echo "a$i"; // Prints a1a2a3. I need it to print a1+a2+a3. } How can I put the loop results into an array and then implode the array with a plus (+) sign resulting in a1+a2+a3? Link to comment https://forums.phpfreaks.com/topic/69224-solved-looping-question-for-all-the-looping-masters/ Share on other sites More sharing options...
Barand Posted September 13, 2007 Share Posted September 13, 2007 <?php $count = 3; $ca = array(); for($i = 1; $i <= $count; $i++) { $ca[] = "a$i"; } echo join ('+', $ca); ?> Link to comment https://forums.phpfreaks.com/topic/69224-solved-looping-question-for-all-the-looping-masters/#findComment-347912 Share on other sites More sharing options...
dubstyleenation Posted September 13, 2007 Author Share Posted September 13, 2007 Amazing. I was pulling my hair out for hours. thanks. Link to comment https://forums.phpfreaks.com/topic/69224-solved-looping-question-for-all-the-looping-masters/#findComment-347923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.