3v4l.org

run code in 300+ PHP versions simultaneously
<?php $source = [ [ "mail_id" => "29848947", "last_name" => "Doe", "first_name" => "Jon", "email" => "jdoe@gmail.com", "status" => "opened" ], [ "mail_id" => "340980398", "last_name" => "Doe", "first_name" => "Jane", "email" => "janedoe@gmail.com", "status" => "sent" ], [ "mail_id" => "877586", "last_name" => "Dwaye", "first_name" => "Jhon", "email" => "Jhondw@yahoo.com", "status" => "clicked" ], [ "mail_id" => "225253463", "last_name" => "Doe", "first_name" => "Jon", "email" => "jdoe@gmail.com", "status" => "opened" ], [ "mail_id" => "849849w4", "last_name" => "Doe", "first_name" => "Jane", "email" => "janedoe@gmail.com", "status" => "sent" ] ]; $result = array_values(array_reduce($source, function($carry, $event) { if(!array_key_exists($event['email'], $carry)) { $carry[$event['email']] = [ "first_name" => $event["first_name"], "last_name" => $event["last_name"], "email" => $event["email"], "opened" => 0, "blocked" => 0, "hard_bounced" => 0, "sent" => 0, "clicked" => 0 ]; } $carry[$event['email']][$event["status"]]++; return $carry; }, [])); print_r($result);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Array ( [0] => Array ( [first_name] => Jon [last_name] => Doe [email] => jdoe@gmail.com [opened] => 2 [blocked] => 0 [hard_bounced] => 0 [sent] => 0 [clicked] => 0 ) [1] => Array ( [first_name] => Jane [last_name] => Doe [email] => janedoe@gmail.com [opened] => 0 [blocked] => 0 [hard_bounced] => 0 [sent] => 2 [clicked] => 0 ) [2] => Array ( [first_name] => Jhon [last_name] => Dwaye [email] => Jhondw@yahoo.com [opened] => 0 [blocked] => 0 [hard_bounced] => 0 [sent] => 0 [clicked] => 1 ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [0] => Array ( [first_name] => Jon [last_name] => Doe [email] => jdoe@gmail.com [opened] => 2 [blocked] => 0 [hard_bounced] => 0 [sent] => 0 [clicked] => 0 ) [1] => Array ( [first_name] => Jane [last_name] => Doe [email] => janedoe@gmail.com [opened] => 0 [blocked] => 0 [hard_bounced] => 0 [sent] => 2 [clicked] => 0 ) [2] => Array ( [first_name] => Jhon [last_name] => Dwaye [email] => Jhondw@yahoo.com [opened] => 0 [blocked] => 0 [hard_bounced] => 0 [sent] => 0 [clicked] => 1 ) )

preferences:
198.06 ms | 403 KiB | 246 Q