It is necessary to come up with an algorithm that would be from such an array

array(3) { [0]=> array(2) { ["forms_email"]=> "max@gmail.com, sm@yandex.ru.ru" ["form_name"]=> "form_compl" } [1]=> array(2) { ["forms_email"]=> "max@gmail.com, 123@da.fwe" ["form_name"]=> "TESTED" } [2]=> array(2) { ["forms_email"]=> "sm@yandex.ru" ["form_name"]=> "formname2" } } 

would do this:

 array(3) { [0]=> array(2) { ["forms_email"]=> "max@gmail.com" ["form_name"]=> "form_compl, TESTED" } [1]=> array(2) { ["forms_email"]=> "123@da.fwe" ["form_name"]=> "TESTED" } [2]=> array(2) { ["forms_email"]=> "sm@yandex.ru" ["form_name"]=> "formname2, form_compl" } } 

that is, for each e-mail you need to specify everything ["form_name"] where there is a match. this is done to send letters, ["form_name"] - the names of the files, then an array will be made of them and will go as an attachment to the letter, therefore, this is the kind needed. array size can be any, as well as the number of recipients

Closed due to the fact that the essence of the question is not clear to the participants of Dmitriy Simushev , VenZell , user194374, aleksandr barakin , D-side 16 Jun '16 at 21:37 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Where is your decision? - user207618
  • Why not try this output array: <? Php array (3) {["max@gmail.com"] => "form_compl, TESTED", ["123@da.fwe"] => "TESTED", ["sm@yandex.ru"] => "formname2, form_compl",} And it will be easy to come up with the algorithm yourself and it will be easy to work afterwards. - uorypm 1:56 pm

1 answer 1

Recalled Hola Challenge .
You can see the work here .
Code (snippet only for spoiler, which needs to be done separately):

 $arr = [[ 'forms_email' => 'max@gmail.com, sm@yandex.ru', 'form_name' => 'form_compl' ], [ 'forms_email' => 'max@gmail.com, 123@da.fwe', 'form_name' => 'TESTED' ], [ 'forms_email' => 'sm@yandex.ru', 'form_name' => 'formname2' ] ]; $tmp = $result = []; foreach($arr as $item){ $subj = trim($item['form_name']); // ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ имя для Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΡ… ΠΌΡ‹Π» $mails = array_map(function($e){return trim($e);},explode(',', $item['forms_email'])); // Π”Π΅Π»ΠΈΠΌ ΠΌΡ‹Π»Π° Π½Π° массив ΠΈ ΠΊΠ°ΠΆΠ΄Ρ‹ΠΉ чистим trim'ΠΎΠΌ foreach($mails as $mail){ if(isset($tmp[$mail])) if(array_search($subj, $tmp[$mail]) !== false) continue; // Если ΡƒΠΆΠ΅ ΠΌΡ‹Π»ΠΎ сущСствуСт ΠΈ такая ΠΌΠ΅Ρ‚ΠΊΠ° Ρƒ Π½ΠΈΡ… Π΅ΡΡ‚ΡŒ, пропускаСм ΠΈΡ‚Π΅Ρ€Π°Ρ†ΠΈΡŽ $tmp[$mail][] = $subj; } } foreach($tmp as $mail => $subj) $result[] = [ // ΠŸΡ€ΠΎΡΡ‚ΠΎ ΠΏΡ€ΠΈΠ²ΠΎΠ΄ΠΈΠΌ ΠΊ Ρ‚Ρ€Π΅Π±ΡƒΠ΅ΠΌΠΎΠΌΡƒ Π²ΠΈΠ΄Ρƒ 'forms_email' => $mail, 'form_name' => implode(', ', $subj) ]; unset($tmp); var_dump($result); 

  • Can I put everything in one line? (written so that you do not read) - Naumov
  • @Naumov, if there is a need ... But it’s better not to do that, writing simple and clear code is more expensive than a pair of ms execution. Who knows PHP can read it, so learn, sir, learn! - user207618 2:57 pm
  • so this is sarcasm, I’ve got you a minus and slapped for the fact that [] wherever possible and impossible, there is generally array_map(function($e){return trim($e);},explode(',', $item['forms_email'])); About single-line if generally keep quiet. - Naumov
  • @Naumov, if you do not like it - you have the right to put a minus, although the solution is working, visual, and fulfills the conditions set. I will not cry. But I’m not going to code in the style that is comfortable for you either, sorry. It is necessary - rewrite for themselves. - user207618