I have a array with following values.I am trying to create a new array using array php array functions and trying to max avoid foreach. The key we are using for new array is "status" and depending on status we make new array for each mail id.
<?php
[
{
"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 or new array as below. I am trying to achieve the below result using any array function like , array_walk_recursive or array_reduce that makes the code look beautiful and compact.
<?php
[
[
"first_name": "Jon",
"last_name": "Doe",
"email": "jdoe@gmail.com",
"opened": 2,
"blocked": 0,
"hard_bounced": 0,
"soft_bounced": 0,
"received": 0,
"clicked": 0
],
[
"first_name": "Jane",
"last_name": "Doe",
"email": "janedoe@gmail.com",
"opened": 0,
"blocked": 0,
"hard_bounced": 0,
"soft_bounced": 0,
"sent": 2,
"clicked": 0
],
[
"first_name": "Jhon",
"last_name": "Dwaye",
"email": "Jhondw@yahoo.com",
"opened": 0,
"blocked": 0,
"hard_bounced": 0,
"soft_bounced": 0,
"sent": 0,
"clicked": 1
],
]