0

I'm having following data:

Array ( [one] => this [two] => this2 )

Which I want to convert to json type which looks like:

data:{[one,this],[two,this2]}

How can I get through this in effecient manner?

Edit: I've tried a lot of things This is actual data which I need to make datatable compatible:

{"draw":0,"recordsTotal":null,"recordsFiltered":null,"data":‌​[[{"first":[""],"sec‌​ond":[""],"third":["‌​"],"fourth":[""],"fi‌​fth":[""],"sixth":["‌​value"]}]]} 

as the data here is in key=>value form json is not compatible for datatables (PHP)

4
  • what did you tried so far? Commented May 28, 2017 at 8:36
  • I've tried a lot of things This is actual data which I need to make datatable compatible: ` {"draw":0,"recordsTotal":null,"recordsFiltered":null,"data":[[{"first":[""],"second":[""],"third":[""],"fourth":[""],"fifth":[""],"sixth":["value"]}]]} ` as the data here is in key=>value form json is not compatible for datatables (PHP) Commented May 28, 2017 at 8:47
  • Chirag, if my answer does not help you reach the solution, then please add what should be converted to what and how is it not doing so. Commented May 28, 2017 at 8:51
  • Please check my comment on your answer Commented May 28, 2017 at 9:01

1 Answer 1

1

You can use array_map and array_keys:

$result = array_map(null, array_keys($array), $array);

$json = json_encode($result);

Here is working demo.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.