Only need to display the value of the array in the JSON output

How to display only array value in JSON outside in php

I am using below php code

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

And he comes back below output

 {"aaData": [ {"id":"31","name":"Elankeeran","email":" ekeeran@yahoo.com ","activated":"0","phone":""} ]} 

But I need JSON output as below

 {"aaData": [ {"31","Elankeeran"," ekeeran@yahoo.com ","0","1234"} ]} 

Can anyone help with this.

+4
source share
3 answers
 $rows = array(); foreach ($user_details as $row) { $rows[] = array_values((array)$row); } echo json_encode(array('aaData'=> $rows)); 

which outputs:

 {"aaData": [ ["31","Elankeeran"," test@yahoo.com ","0","1234"], ["33","Elan"," test@gmail.com ","1",""] ]} 
+7
source
 echo '{"aaData":'.json_encode(array_values($user_details)).'}'; 

gotta do it

+1
source

Your PHP already produces valid JSON. To access elements in it from JavaScript, use patterns such as:

 obj.aaData[0].name; // Elankeeran obj.aaData[0].email; // email@yahoo.com 
+1
source

Source: https://habr.com/ru/post/1392204/


All Articles