i'm using mongodb and my result of find is this one
> db.analysis.find().pretty()
{ "_id" : "a", "age" : [ "d" ] }
{ "_id" : "b", "age" : [ "a", "b", "e" ] }
Here is the query I use in php:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new MongoDB\Driver\BulkWrite;
$query = new MongoDB\Driver\Query([]);
$rows = $mng->executeQuery("whot.analysis", $query);
$return_array = array();
foreach ($rows as $row) {
array_push($return_array,
array(
"_id" => "$row->_id",
"age" => "$row->age"
));
}
$json= json_encode($return_array);
echo $json;
As a result
Notice: Array to string conversion in /usr/local/nginx/html/mongo_analysis.php on line 39
Notice: Array to string conversion in /usr/local/nginx/html/mongo_analysis.php on line 39
[{"_id":"a","age":"Array"},{"_id":"b","age":"Array"}]
Can anyone let me know how to change the code?
i want to change Array to string..