E
E
EvgMul2018-10-07 21:30:30
PHP
EvgMul, 2018-10-07 21:30:30

How to properly convert an array to json?

Hello. I have an array like:

Array
(
    [0] => [email protected]
    [1] => [email protected]
)

I need to convert it to json like this:
[
  {
    "email": "[email protected]",
  },
  {
    "email": "[email protected]",
  }
]

Please tell me how to do it. Regular json_encode() won't help here.
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2018-10-07
@EvgMul

$data = array_map(function($email) {
  return ['email' => $email];
}, $data);
https://ideone.com/AvYwkX

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question