sevfurneaux Posted October 27, 2011 Share Posted October 27, 2011 Hi there, I'm relatively new to Processwire (and PHP!) and have the following question: I'm currently looping through the images field as shown below: foreach($page->images as $image) { $large = $image->size(1200, 795); echo "{$large->url},"; } You'll notice that there is a comma after the {$image->url}. I would like to be able to check in the loop if it is the last image and if so, the comma is not shown. Would appreciate the help! Cheers, Sev Link to comment Share on other sites More sharing options...
Soma Posted October 27, 2011 Share Posted October 27, 2011 Hi sev and welcome! You could do the following and strip the last char from the string after the loop. <?php // if there's any images if(count($page->images)){ $out = ''; foreach($page->images as $image) { $large = $image->size(1200, 795); $out .= "{$large->url},"; } echo substr($out, 0, -1); } Link to comment Share on other sites More sharing options...
sevfurneaux Posted October 27, 2011 Author Share Posted October 27, 2011 Works perfectly – Thanks Soma! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now