Jump to content

Recommended Posts

Hello all,

  I have a slight problem that I need help with. I am working on a php newsletter script. What I am trying to do is figure out how to format the output of an array (displays to the admin all of the email addresses that were sent-to); my array name is '$list'. As it is now say I select 20 users for receiving the newsletter/message. After it is sent the output to the admin screen would be:

Message Sent To:

xxx@x.com, xxx@x.com, xxx@x.com, etc. etc. etc. for a continuos horizontal line of 20 email addresses seperated by a comma and a space.

What I need to do is manipulate the array dropping the ', ' (comma and a space), display 4 email addresses then break and display the next 4 etc.

Any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/165692-solved-array-manipulation/
Share on other sites

If $list is an array. You can use array_chunk to cut your $list array into smaller arrays which hold 4 emails each. Then you can do

$rows = array_chunk($list, 4);
foreach($rows  as $emails)
{
    echo implode(', ', $emails) . '<br />';
}

@Crayon Violet:  Thanks but I'm there already!

 

If $list is an array. You can use array_chunk to cut your $list array into smaller arrays which hold 4 emails each. Then you can do

$rows = array_chunk($list, 4);
foreach($rows  as $emails)
{
    echo implode(', ', $emails) . '<br />';
}

 

Thanks 'wildteen88'. This completely solved my problem. Had to change it a little though; I forgot that $list was already a string derived from the array which is simply $array. So I changed it to this:

array_chunk($array, 2);

I decided on 2 addresses across instead of 4. This works perfectly! Thanks again !

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.