stig1 Posted November 29, 2010 Share Posted November 29, 2010 I have the following foreach statement that gets the error msg's from the array called errors. However for the last key in the array, i would not like the <br /> to be echo'd out. How can I achieve that? foreach ($errors as $msg) { echo $msg; echo "<br />"; } Link to comment https://forums.phpfreaks.com/topic/220162-foreach-array-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2010 Share Posted November 29, 2010 $string = implode('<br />',$errors); echo $string; Link to comment https://forums.phpfreaks.com/topic/220162-foreach-array-help/#findComment-1141044 Share on other sites More sharing options...
stig1 Posted November 29, 2010 Author Share Posted November 29, 2010 but wont that get rid of them all? or only the last <br /> in the array? for example: error 1: no items<br /> error 2: no qty<br /> so output would look like error 1: no items<br /> error 2: no qty Thats what I am looking to achieve. Link to comment https://forums.phpfreaks.com/topic/220162-foreach-array-help/#findComment-1141047 Share on other sites More sharing options...
Pikachu2000 Posted November 29, 2010 Share Posted November 29, 2010 Hint: implode()'s first parameter is the separator to be used between each array element. Link to comment https://forums.phpfreaks.com/topic/220162-foreach-array-help/#findComment-1141056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.