Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to display only array value in JSON output

Tags:

json

php

How to display only array value in JSON out in php

I am using below PHP code

echo '{"aaData":'.json_encode($user_details).'}';

And it return below output

{"aaData": [
    {"id":"31","name":"Elankeeran","email":"[email protected]","activated":"0","phone":""}
]}

But I need JSON output like below

{"aaData": [
    {"31","Elankeeran","[email protected]","0","1234"}
]}

Any one please help on this.

like image 556
Elankeeran Avatar asked Jan 17 '23 17:01

Elankeeran


2 Answers

$rows = array();
foreach ($user_details as $row) {
  $rows[] = array_values((array)$row);
}

echo json_encode(array('aaData'=> $rows));

which outputs:

{"aaData": [
    ["31","Elankeeran","[email protected]","0","1234"],
    ["33","Elan","[email protected]","1",""]
]}
like image 193
Dor Shemer Avatar answered Jan 25 '23 23:01

Dor Shemer


echo '{"aaData":'.json_encode(array_values($user_details)).'}';

should do it

like image 39
rauschen Avatar answered Jan 26 '23 00:01

rauschen