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 />"; } Quote 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; Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/220162-foreach-array-help/#findComment-1141056 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.